PHP Classes

File: UsageExample.txt

Recommend this page to a friend!
  Classes of Roy Toledo  >  MySQL Wrapper Class 2  >  UsageExample.txt  >  Download  
File: UsageExample.txt
Role: Documentation
Content type: text/plain
Description: class.mysqldb Usage Example
Class: MySQL Wrapper Class 2
MySQL database access wrapper
Author: By
Last change:
Date: 11 years ago
Size: 1,818 bytes


Class file image Download
Some Usage Examples 

First To Connect To A Mysql DB You Need To Set The Following Constants
	define('DBHost','~YOUR HOST~');
	define('DBUser','~YOUR USER NAME~');
	define('DBPassword','~YOUR PASSWORD~');
	define('DBDefaultDatabase','~Default DB~'); 
and create new object
	$db = new dbWrapper();

In order to work with multiple databases use 
Select all columns in a table (*) [second argument optional]
	$db->selectTable('my_table', "firstname = 'john'");
Get one row query result as MYSQL_ASSOC
	$row = $db->queryRow($sql);	
Run Query
	Handle result:
	Get All Returned Rows as a 3D Array
Check if query returned results:
	$db->hasResults(); [returns false if empty, number of rows if full]
INSERT INTO my_table (firstname,lastname) VALUES ('john', 'doh');
will now be
$db->insert(array('firstname'=>'john', 'lastname'=>'doh'),'my_table');

Same syntax for replace and update, if your table uses a different Primary Key from "id" on update you need to specify your primary key as so
$db->update(array('firstname'=>'john', 'lastname'=>'doh'),'my_table', 'user_id');
	* Will Automaticly switch ' charecter with ` on string (can be set to use mysql_escape_string or anything else instead) 

Get Last Insert ID

to begin a transaction use
following will commit or rollback if a failure had accured in the transaction (will return true for commit and false if rollback)

Backup Table - will backup a whole table and add the date to the new table name 
For easy debug turn debugging on 
	$db->debug = true;
For more information send a message to info at phpclasses dot org.