PHP Classes

File: example.MySQL.php

Recommend this page to a friend!
  Classes of Richard Munroe   dm.DB   example.MySQL.php   Download  
File: example.MySQL.php
Role: Example script
Content type: text/plain
Description: Example for MySQL
Class: dm.DB
Generic database access wrapper
Author: By
Last change:
Date: 17 years ago
Size: 2,012 bytes


Class file image Download

 * @author Dick Munroe <>
 * @copyright copyright @ 2006 by Dick Munroe, Cottage Software Works, Inc.
 * @license
 * @version 1.0.0
 * @package dm.DB
 * @example ./example.php

 * This script assumes that the MySQL database created by DB.sql exists.


"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()) {

/* 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");

/* 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()) {

/* optional clearing of result set before issuing a "SELECT" statement */

/* Begin a transaction, INSERT a new record and get the last inserted id */
$db->queryConstant("INSERT INTO `table` SET user = 'am', password = 'am2'");

/* diconnect and show errors */