PEAR & MDB2
Posted by: atac (---.ip.tiscali.nl)
Date: February 07, 2008 12:58PM

Dear fellow forum users,

I think this is a new topic, I have try searching for threats with the key words PEAR & MDB2, but that yield no results. This tropic is about accessing the database using the new(sometime I wonder if it is improved) method of MDB2, I got the same script to work under the old DB PEAR method than I got a message about the new MDB2 method.

I am also using a Wamp 5 Server Version 2.0 to test run everything.

I have try running the script in its entirety, but that resulted in an error message. I than broke the script up into sections(see script chunks below) and build in an echo statement to check that it was working. everything seem fine until it try to query the database, than the same error message appear.



<?php
include('db_login.php');
require_once('MDB2.php');

//translate our db login info into an array
$dsn = array(
'phptype'=> 'mysql',
'username'=> $username,
'password'=> $password,
'hostspec'=> $host,
'database'=> $database
);

//create the connection as an MDB2 instance
$mdb2 = MDB2::factory($dsn);
if (PEAR::isError($mdb2)){
die($mdb2->getMessage());
}

echo $mdb2;

//set the fetchmode to field associative
$mdb2->setFetchMode(MDB2_FETCHMODE_ASSOC);

$query = "SELECT * FROM books NATURAL JOIN authors";
$result = $mdb2->query($query);
if (PEAR::isError($result)){
die ("Could not query the database:<br/>$query".$result->getMessage());
}

echo $result;

?>


ERROR MESSAGE from the server.

MDB2_Driver_mysql: (phptype = mysql, dbsyntax = mysql)Could not query the database:
SELECT * FROM books NATURAL JOIN authorsMDB2 Error: connect failed

As you can see the connection is ok; it return a value besides an error. But the query part it just doesn't like.

I have also consulted a PEAR book and the structure from that book is very simular to the above code. Only they use different variable(ie, instead of $query they use $sql-but that should make no difference should it? so long as I am consistent with using that variable throughout the script.) I have try following the example from the PEAR book and that result in the same error message.

Has anyone encounter this problem before; if yes -could you direct me to the solution, if no -could you suggest what I can try to remedy this situation?



Thank you.

Options: ReplyQuote
Re: PEAR & MDB2
Posted by: atac (---.ip.tiscali.nl)
Date: February 20, 2008 11:14AM

Dear all user,

after playing around with the code snipbit for a few days. I appears that the MDB2 method does not like the include statement. so I manually type in the information myself. So that is one solution to my problem,
if someone else discover another way can they post it here. I would be interested in how they solved this problem.

Sincerely,

atac.

Options: ReplyQuote


Sorry, only registered users may post in this forum.