...

View Full Version : MDB2 Error: connect failed



RiskyShenanigan
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


<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>test_mdb2</title>
</head>

<body>
<?php

require_once 'MDB2.php';

$dsn = array(
'phptype' => 'mysql',
'username' => 'user1',
'password' => 'testpass1',
'hostspec' => '127.0.0.1',
'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)) {
die($mdb2->getMessage());
}

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

if (PEAR::isError($res)) {
die($res->getMessage());
}

// Disconnect
$mdb2->disconnect();


?>
</body>
</html>

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?

Fou-Lu
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);
error_reporting(E_ALL);


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?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum