Hi guys!
I keep getting the following error message in PHP: “SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected error”.
My Code:
[code=php]
<?php
$db_host = ‘localhost’;
$db_user = ‘root’;
$db_pswd = ”;
$db_name = ‘mysql’;
try {
$conn = new PDO(“mysql:host = {$db_host}; dbname = {$db_name}”, $db_user, $db_pswd);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$query = $conn->query(“SELECT * FROM help_topic”);
while( $row = $query->fetch(PDO::FETCH_OBJ) ) {
$fetched_obj[] = $row;
}
print_r($fetched_obj);
} catch(PDOException $e) {
echo ‘Error: ‘ . $e->getMessage();
}
?>
I’ve been searching for days now on the internet and it’s seems that this error message is really a common thing, but most of the time it’s due to poor syntax, which is not the case in my particular situation.
Any guesses?