PDO Error: SQLSTATE[3D000]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

PDO Error: SQLSTATE[3D000]

Post by social_experiment »

I'm connecting to an SQL database using PDO and when i attempt to execute one of the queries i receive the message below

Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected in nanya.php on line 145

Below is the snippet of code where the error is generated.

Code: Select all

<?php
$countSql = "SELECT 
			COUNT(`id`) 
			FROM 
			`users`
			WHERE 
			`users_email` = ?";			
			
			$sth = $this->_dbh->prepare($countSql);
			$sth->execute(array($this->_username)); // line 145
?>
The username & password combination is correct, tested them outside of the script and changed the password to a different one.

I did a search for this problem one the internet and tried some of the suggested 'solutions' but nothing has worked to solve the issue. Any ideas would be welcome.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PDO Error: SQLSTATE[3D000]

Post by Celauran »

Have you checked the DSN string? mysql:host=localhost rather than mysql:localhost, for example
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: PDO Error: SQLSTATE[3D000]

Post by social_experiment »

Celauran wrote:Have you checked the DSN string?
i tried both options because i saw similar advice on stackoverflow but no luck;
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Post Reply