<?php
//assume you have these set somewhere
global $db_user, $db_password, $db_host, $db_name;
$sqlcall = new SQLCall($db_user, $db_password, $db_host, $db_name);
//"true" as a parameter to this method will print out the error message
//if any exists. Method returns true or false so can be used in conditionals.
$sqlcall->hadErrors(true);
//set up a select statement to show off the goods
$sqlcall->doSelect("SELECT id, member_id AS mid FROM visitors", false);
print "This select retrieved " . $sqlcall->getFieldCount() . " columns per row.<BR>";
while( $sqlcall->getNext() ){
//The beauty of simplicity - the object sets member variables corresponding
//to the names of each of the columns in the result set, so that you can
//simply do $sqlcall-><column name> to access the result. Notice how
//aliases are handled seamlessly
print "ID: $sqlcall->id, Member ID: $sqlcall->mid<BR>";
//all results are also available as $sqlcall->f<n> where n is a 1-based
//index. This is good for generic processing.
print "Alternative (should be the same output): ID: $sqlcall->f1, Member ID: $sqlcall->f2<BR>";
}//while
//There is no column "x" in this table - expect an error here.
//The error is written into a comment in the source HTML.
$sqlcall->doDelete("DELETE FROM visitors WHERE x = -1");
if( ! $sqlcall->hadErrors(true) ){
print "Ok on the delete.<BR>";
}//if
//always finalize the sqlcall object
$sqlcall->finalize();
?>
|