Hey fellas No idea what i'm doing wrong already tried all suggested idea on stackoverflow still not resolving error no database selected.
code:
<?php
include 'db_connect.php';
// create client table
try {
$sql = 'CREATE TABLE client (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
name VARCHAR(40) NOT NULL,
phone INT NOT NULL,
email VARCHAR(60) NOT NULL,
address TEXT
) DEFAULT CHARACTER SET utf8 ENGINE=InnoDB';
$pdo->exec($sql);
}
catch(PDOException $e) {
$error = 'Error creating customer table: '.$e->getMessage();
include 'error.html.php';
exit();
}
$output = "Customer table created succesfuly";
include 'output.php';
?>
db_connect.php code:
<?php
$host = "localhost";
$db = "hotelDB";
$dbuser = "hotelAuth";
$password = "+_90-w4903nsdkfn";
// connecting to DB using PDO
try {
$pdo = new PDO("mysql:host = {$host}; dbname = {$db}", "{$dbuser}", "{$password}");
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo->exec('SET NAMES "utf8"');
}
catch(PDOException $e) {
$error = "Error Occured While Connecting TO Database: ".$e->getMessage();
include 'error.html.php';
exit();
}
// On successful connection include booking form.
$ack = "Secure Connection established.";
?>

$dbuser, $password.include 'error.html.php';- you should be doing it inthe error handler but not in the catch block."mysql:host=$host;dbname=$db". PDO stops parsing it at the first space and uses defaults, and that's what your problem is."{$dbuser}"and"{$password}"are unnecessarily quoted. Those are just method parameters, and can be passed as$dbuser, $passwordwithout any quotes.