Page 1 of 1

PDO Error: SQLSTATE[3D000]

Posted: Sun Feb 16, 2014 8:05 am
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.

Re: PDO Error: SQLSTATE[3D000]

Posted: Sun Feb 16, 2014 9:00 am
by Celauran
Have you checked the DSN string? mysql:host=localhost rather than mysql:localhost, for example

Re: PDO Error: SQLSTATE[3D000]

Posted: Sun Feb 16, 2014 11:21 am
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;