Nitish Nitish - 1 year ago 158
MySQL Question

PDO returns empty object

I have a connection as below :

$dsn = 'mysql: host=localhost; dbname=ami';
$user = 'root';
$password = 'password';
try {
$pdo = new PDO($dsn, $user, $password); var_dump($pdo);
catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();

But the output is
object(PDO)#1 (0) { }
. I am clueless whats wrong !

Answer Source

It is not an empty object. var_dump is showing you less information about that returned object.

In my case. this is my output with var_dump


If you want to see more detailed information. Use symfony var_dumper component.

Here is it's output.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download