/    Sign up×
Community /Pin to ProfileBookmark

PHP Error: SQLSTATE[3D000]

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();
}

?>
[/code]

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?

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@NogDogOct 08.2017 — Does the error output indicate if it's the new PDO instantiation that is failing, or the query()?
Copy linkTweet thisAlerts:
@ginerjmOct 09.2017 — I am going to ask the obvious: What is your database name? Not your database type, but the specific database that holds this table? You are using 'mysql' but that seems very simplistic for a dbname, so I am wondering if there is some confusion.
×

Success!

Help @WebNewBie1 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.21,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...