I am having trouble getting the PEAR DB or MDB2 classes to connect to my db, while the native mysql db functions connect fine.
The following connection method works fine ...
OUTPUT: [highlight][tt]Name: 1[/tt][/highlight]
However, the following triggers an error:
The error is thrown where the bold line is:
OUTPUT: [highlight][tt]Error while connecting : DB Error: connect failed[/tt][/highlight]
So basically, the native mysql db functions are able to connect, but using PEAR DB class, or the MDB2 class for that matter (I've tried them both), causes an error. As you can see, I am using variables for the connection, so the credentials are not an issue
One thing to note is that this server doesn't have pear installed, so I am including it locally which I have done plenty of times with no problem, but not sure if it would cause an error here. It obviously is using the PEAR libraries fine and I did update the include path to have the local pear directory in it. Also, I have error_reporting set to E_ALL and display_errors set to 1 and am not getting any other errors.
any help is greatly appreciated.
Thanks
The following connection method works fine ...
Code:
$hostname='myhost.com';
$username='user;
$password='foo';
$dbname='bar';
$usertable='foobar';
$yourfield = 'id';
mysql_connect($hostname,$username, $password) OR DIE ('Unable to connect to database! Please try again later.');
mysql_select_db($dbname);
$query = "SELECT * FROM $usertable";
$result = mysql_query($query);
if($result) {
while($row = mysql_fetch_array($result)){
$name = $row[$yourfield];
echo 'Name: '.$name;
}
}
However, the following triggers an error:
Code:
$hostname='myhost.com';
$username='user;
$password='foo';
$dbname='bar';
$usertable='foobar';
$yourfield = 'id';
require_once("DB.php");
$dburl = "mysql://$username:@$password@$hostname:3306/$dbname";
$con = DB::connect($dburl);
if(PEAR::isError($con)) {
[b]die("Error while connecting : " . $con->getMessage());[/b]
}
$sql = "SELECT * FROM Expenses";$resultset = $con->query($sql);
if(PEAR::isError($resultset)) {
die('Failed to issue query, error message : ' . $resultset->getMessage());
}
while($row = $resultset->fetchRow(MDB2_FETCHMODE_ASSOC)) {
foreach($row as $field => $value) {
echo "$key / $value \n";
}
}
The error is thrown where the bold line is:
OUTPUT: [highlight][tt]Error while connecting : DB Error: connect failed[/tt][/highlight]
So basically, the native mysql db functions are able to connect, but using PEAR DB class, or the MDB2 class for that matter (I've tried them both), causes an error. As you can see, I am using variables for the connection, so the credentials are not an issue
One thing to note is that this server doesn't have pear installed, so I am including it locally which I have done plenty of times with no problem, but not sure if it would cause an error here. It obviously is using the PEAR libraries fine and I did update the include path to have the local pear directory in it. Also, I have error_reporting set to E_ALL and display_errors set to 1 and am not getting any other errors.
any help is greatly appreciated.
Thanks