View Full Version : MDB2 Error: connect failed

11-13-2011, 12:18 PM
Hi, I am trying to set up the Pear MDB2 package, with the MySQL driver. I have installed all the necessary stuff and have tried to execute a simple query SELECT statement however I keep getting the message: -

MDB2 Error: connect failed

<meta charset="utf-8">


require_once 'MDB2.php';

$dsn = array(
'phptype' => 'mysql',
'username' => 'user1',
'password' => 'testpass1',
'hostspec' => '',
'database' => 'people',

$options = array(
'debug' => 2,
'portability' => MDB2_PORTABILITY_ALL,

// uses MDB2::factory() to create the instance
// and also attempts to connect to the host
$mdb2 = MDB2::factory($dsn, $options);

if (PEAR::isError($mdb2)) {

$res = $mdb2->query('SELECT * FROM user');

if (PEAR::isError($res)) {

// Disconnect


Also the include_path need to have the file path to my pear folder? Currently it is set as .;C:\php\pear, since I am using WAMP do I need it for the C:\wamp\bin\php\pear folder?

11-13-2011, 06:31 PM
It doesn't look to me like you have a filepath issue, otherwise you should see errors referring to undeclared classes. You can double check by making sure your error reporting is open:

ini_set('display_errors', 1);

I personally never use pear extensions since there is no guarantee that it will be available. Why not use a PDO instead of an MDB2?