PHP Classes Tutorial 1 - Database Abstraction and Classes Tutorial - Page 7 of 7
Example Usage
Just a little example of how to use your new class, basically the same as you would use any other class;
<?php
include_once 'phpDBConnector.php';
// make new object, called $db
$db = new phpDBConnector( 'localhost', 'user', 'password' );
// select db
$db->selectDB( 'dbname' );
// execute some sql
$sql = 'SELECT id FROM .....';
$sql_query = $db->query( $sql ); // replace this with your own vaild sql
// get the results and echo them
while ( $sql_row = $db->fetch_object( $sql_query ) )
{
echo 'ID: ' . $sql_row->id . '<br>';
}
?>
Hopefully the above code should be fairly self explanatory, any problems, email me!
