Configure the Database Connection
On the Php code add the following database connection script to check your existing database on
the MySQL server
php
//DATABASE CONNECTION
$host = 'localhost';
$db = 'it30_lab_db';
$user = 'root';
$pass = '';
$charset = 'utf8mb4';
$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
$options = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
try {
$pdo = new PDO($dsn, $user, $pass, $options);
} catch (PDOException $e) {
die("Database connection failed: " . $e->getMessage());
}
echo scripts to on the try catch block to check if the connection had succeed or failed.
Sign in to save your progress permanently.
Progress is saved in your browser session
Step 3 of 5