| 
<?php
 /**
 * @author Dick Munroe <[email protected]>
 * @copyright copyright @ 2006 by Dick Munroe, Cottage Software Works, Inc.
 * @license http://www.csworks.com/publications/ModifiedNetBSD.html
 * @version 1.0.0
 * @package dm.DB
 * @example ./example.php
 */
 
 /*
 * This script assumes that the MySQL database created by DB.sql exists.
 */
 
 error_reporting(E_ALL);
 
 include_once "class.factory.DB.php" ;
 
 /*
 * Put the value of your database login name into this variable.
 */
 
 $dblogin = "put your login name here" ;
 
 /*
 * Put the value of your database login password into this variable.
 */
 
 $dbpassword = "put your password here" ;
 
 /*
 * Should you change the name of the database created by DB.sql, then
 * put the new name in the following variable.
 */
 
 $dbdatabase = "DB" ;
 
 $db = FactoryDB::factory($dblogin, $dbpassword, $dbdatabase);
 $db->queryConstant("SELECT fullname FROM `table` LIMIT 10");
 
 /* loop through several rows of data */
 while ($db->fetchRow()) {
 echo $db->record["fullname"]."<br>\n";
 }
 
 /* this will echo "10" as the result count */
 echo $db->resultCount()."<br>\n";
 
 /* example of retrieving only one record and displaying it */
 $db->queryConstant("SELECT fullname FROM `table` LIMIT 1");
 $db->fetchRow();
 echo $db->record["fullname"]."<br>\n";
 
 /* this will echo "1" as the result count */
 echo $db->resultCount()."<br>\n";
 
 /* if there were any records from the previous SELECT query, then "WOOHOO" will be printed */
 if ($db->resultExist()) {
 echo "WOOHOO";
 }
 
 /* optional clearing of result set before issuing a "SELECT" statement */
 $db->clear();
 
 /* Begin a transaction, INSERT a new record and get the last inserted id */
 $db->beginTransaction();
 $db->queryConstant("INSERT INTO `table` SET user = 'am', password = 'am2'");
 echo "<br>".$db->fetchLastInsertId()."<br><br>\n";
 $db->commitTransaction();
 
 /* diconnect and show errors */
 $db->disconnect();
 $db->showErrors();
 
 ?>
 
 |