error related to PEAR DB and oop
Posted: Thu Jul 12, 2007 5:16 pm
feyd | Please use
Any ideas on what's causing the error? Thanks for any help.
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Hi, I'm trying to get the PEAR DB installed, but I'm getting this error when I try it:
"Fatal error: Call to a member function query() on a non-object in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\pear_test.php on line 36"
My code is as follows (I commented line 36):Code: Select all
<?php
include('db_login.php');
require_once('DB.php');
$connection = mysql_connect($db_host, $db_username, $db_password);
if (!$connection){
die ("Could not connect to the database: <br />". mysql_error());
}
$dbname = 'test';
$db_select = mysql_select_db($dbname);
if (!$db_select){
die ("could not select the database: <br />". mysql_error());
}
echo "connected to $dbname <br /><br />";
$query = "select * from books natural join authors";
$result = $connection->query($query); //<<<<<<<<<<<<<<<<<<<<< LINE 36
if (DB::isError($result)){
die ("could not query the database: <br />".$query." ".DB::errorMessage($result));
}
echo('<table border="1">');
echo '<tr><th>Title</th><th>Author</th><th>Pages</th></tr>';
while ($result_row = $result->fetchRow()){
echo "<tr><td>";
echo $result_row[1] . '</td><td>';
echo $result_row[4] . '</td><td>';
echo $result_row[2] . '</td></tr>';
}
echo("</table>");
$connection->disconnect();
?>Any ideas on what's causing the error? Thanks for any help.
feyd | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]