connection = new PDO("mysql:host=" . self::$servername, self::$username, self::$password); $this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // Make sure the actual db exists $createDBQuery = "CREATE DATABASE IF NOT EXISTS " . self::$dbname . ";"; $this->connection->exec($createDBQuery); // Make the actual connection to the database $this->connection->exec("USE " . self::$dbname); } function createTable(string $tableName, array $columns) { $query = "CREATE TABLE IF NOT EXISTS {$tableName}( id INT NOT NULL AUTO_INCREMENT,"; foreach ($columns as $column) { $query .= "{$column},"; } $query .= "PRIMARY KEY (id));"; $this->connection->exec($query); } function getAllValues(string $tableName) { $sth = $this->connection->prepare("SELECT * FROM `{$tableName}`"); $sth->execute(); return $sth->fetchAll(PDO::FETCH_OBJ); } }