Need help with PHP, MySQL and PEAR/MDB2
I'm trying to get up to speed with PHP/MySQL programming and am writing a test program using the MDB2 portion of the PEAR library to access a database. I'm using the following code:
Alternatively, does anyone know of a good PHP/MySQL development forum where I can ask this sort of question?
<?php
$page_title = "Database Test"; // required by htmlhead.php
require_once("../htmlhead.php"); // Standard XHTML <head> section
require_once("../sqllogin.php"); // $dbtype, $sqlserver, $sqlusername, $sqlpassword, $dbname defined
require_once("MDB2.php"); // PEAR MDB2
$connection = MDB2::factory($dbtype.'://'.$sqlusername.':'.$sqlpassword.'@'.$sqlserver.'/'.$dbname);
if (PEAR::isError($connection)){
die("<p>Could not select database \"" . $connection->getMessage() . "\".</p>");
}
$sql = "SELECT * FROM licenses";
$licensetypes = $connection->query($sql);
if (PEAR::isError($licensetypes)){
die('Could not query the database:<br />'. $licensetypes->getmessage());
}
echo '<table>';
while ($license = $licencetypes->fetchRow(MDB2_FETCHMODE_ASSOC)) {
echo '<tr><td>';
echo $license[0] . '</td><td>';
echo $license[1] . '</td></tr>';
}
echo '</table>';
mysql_close();
require_once("../htmlfoot.php");
?>
based mostly on instructions found here but I'm getting the following error:
Fatal error: Call to a member function fetchRow() on a non-object in /home/diguana/phpsite/html/dbtest.php on line 25The "licenses" table has two colums and currently has three rows of data entered, which display without a problem when I type "SELECT * FROM licenses;" from within the MySQL commandline utility. Anyone know what I'm doing wrong?
Alternatively, does anyone know of a good PHP/MySQL development forum where I can ask this sort of question?
Comments
I'll look at this tomorrow when I'm not so tired. (Connecting to a database and running a query can be done in just a few lines of code. I still want to know what advantage doing it with PEAR holds that makes it worth taking 30 lines to do the same thing, though.)
"$licencetypes" is not "$licensetypes". It's a just typo as is the case at least 90% of the time I think.