Page 1 of 1

Cannot instantiate non-existent class: pdo in....

Posted: Mon Nov 09, 2009 12:37 pm
by TecNik
Hi there,

I'm a newbie to php and have been working my way through some tutorials however I'm coming up with the following error:

Cannot instantiate non-existent class: pdo in...

The line I'm pointed to contains this:

Code: Select all

$db = new PDO(DB_INFO, DB_USER, DB_PASS);
Which is preceeded by this:

Code: Select all

include_once 'db.inc.php';
This include file contains this code:

Code: Select all

<?php
 
define('DB_INFO', 'xxx');
define('DB_USER', 'yyy');
define('DB_PASS', 'zzz');
 
?>
I've been able to test a connection to the database using this:

Code: Select all

<?php
$link = mysql_connect('xxx', 'yyy', 'zzz');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
And, that works fine and a connection is made.

Please can someone point me in the right direction.
I'm replacing the xxx, yyy and zzz with the database name, username and password.

Thanks in advance.

Regards,

Nick

Re: Cannot instantiate non-existent class: pdo in....

Posted: Wed Nov 18, 2009 7:23 am
by Weiry
The first thing you should do is check to see if you have PDO enabled, or if you have the required version of PHP.
PDO Installation

Also, check out this link for a guide on PDO
Intro to PHP PDO

The second thing you should do is check your connection information matches up with the PDO Constructor.
Example:

Code: Select all

<?php
/* Connect to an ODBC database using driver invocation */
$dsn = 'mysql:dbname=my_database_name;host=127.0.0.1';
$user = 'username';
$password = 'password';
 
try {
    $dbh = new PDO($dsn, $user, $password);
    if($dbh){
        print "Connection successful!";}
} catch (PDOException $e) {
    echo 'Connection failed: ' . $e->getMessage();
}
?>