I've been researching and trying to figure out what's stopping the connection for 2 days.. Can't seem to figure it out.
I've got my config.php:
<?php
$host = 'localhost';
$dbname = 'test';
$username = 'root';
$password = 'root';
$charset = 'utf8mb4';
$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MDOE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
$dsn = "mysql:host=$host;dbname=$dbname";
?>
Then I have an install.php which allows for my database and table to be created on the server:
<?php
require 'config.php';
try {
$connection = new PDO("mysql:host=$host", $username, $password, $options);
$sql = file_get_contents("data/init.sql");
$connection->exec($sql);
echo "Database and table has been created successfully.";
} catch (PDOException $error) {
echo $sql . "<br>" . $error->getMessage();
}
?>
And lastly I have the actual init.sql that creates the database:
CREATE DATABASE test;
USE test;
CREATE TABLE users (
id INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstName VARCHAR(30) NOT NULL,
lastName VARCHAR(30) NOT NULL,
);
I go into localhost and click the install.php in the directory, which should install the database, but it just gives me HTTP Error 500, I assume because it's not connecting properly.
Is there anything you guys are noticing that I've missed?