lmaster Posted December 21, 2008 Share Posted December 21, 2008 Fellow Freaks: I'm trying to run this script PHP script to retrieve results from a mySQL database using MDB2. (THIS WORKS WITH mysqli, SO IT IS NOT THE DB, access issues, etc!). The problem is that it is hanging trying to call the method MDB2_Error::query(). I should note that I had to manually move the MDB2.php to the c:\php directory becasue it was hanging prior on not being able to find that file as specified in the require_once directive in the script below. I already did a install mdb2 and install mdb2_driver_mysql. ***************START SCRIPT****************** <html> <head> <title>Book-O-Rama Search Results</title> </head> <body> <h1>Book-O-Rama Search Results</h1> <?php // set up for using PEAR MDB2 require_once('MDB2.php'); $user = 'root'; $pass = 'sesame'; $host = 'localhost'; $db_name = 'books'; // set up universal connection string or DSN $dsn = "mysqli://".$user.":".$pass."@".$host."/".$db_name; // connect to database $db = &MDB2::connect($dsn); // check if connection worked if (MDB2::isError($db)) { echo $db->getMessage(); } // perform query $query = "select * from books where ".$searchtype." like '%".$searchterm."%'"; $result = $db->query($query); // check that result was ok /* if (MDB2::isError($result)) { echo $db->getMessage(); exit; } */ // get number of returned rows $num_results = $result->numRows(); // display each returned row for ($i=0; $i <$num_results; $i++) { $row = $result->fetchRow(MDB2_FETCHMODE_ASSOC); echo "<p><strong>".($i+1).". Title: "; echo htmlspecialchars(stripslashes($row['title'])); echo "</strong><br />Author: "; echo stripslashes($row['author']); echo "<br />ISBN: "; echo stripslashes($row['isbn']); echo "<br />Price: "; echo stripslashes($row['price']); echo "</p>"; } // disconnect from database $db->disconnect(); ?> </body> </html> **********************END SCRIPT************************ ************RESULT OF RUNNING THE SCRIPT*************************** C:\php>php results_generic.php <html> <head> <title>Book-O-Rama Search Results</title> </head> <body> <h1>Book-O-Rama Search Results</h1> MDB2 Error: not foundPHP Notice: Undefined variable: searchtype in C:\php\resul ts_generic.php on line 29 PHP Notice: Undefined variable: searchterm in C:\php\results_generic.php on lin e 29 PHP Fatal error: Call to undefined method MDB2_Error::query() in C:\php\results _generic.php on line 31 Link to comment https://forums.phpfreaks.com/topic/137941-help-with-using-mdb2-works-with-mysqli/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.