Paged selection

Call QueryExe passing true as the third parameter; returns the number of records

function SelectAll( &$rows, $param )
{
 $db =& Db::globaldb();
 $rows = array();
 $sqlstr = "SELECT field FROM table WHERE id='$param'";
 return $db->QueryExe($rows, $sqlstr, true);
}

Array selection

Call QueryExe with no other parameters (it defaults to array selection); returns the number of records

function SelectAll( &$rows, $param )
{
 $db =& Db::globaldb();
 $rows = array();
 $sqlstr = "SELECT field FROM table WHERE id='$param'";
 return $db->QueryExe($rows, $sqlstr);
}

Single record selection

function SelectOne( &$row, $param )
{
 $db =& Db::globaldb();
 $row = array();
 $sqlstr = "SELECT field FROM table WHERE id='$param'";
 $db->query_single($row, $sqlstr);
 return $row;
}

Insert

Do not assume the auto_increment for the primary key; always get it with the NextId function.

function InsertRecord( $value1, $value2 )
{
 $db =& Db::globaldb();
 $db->begin();
 $db->lock( "mytable" );
 $nextid = $db->NextId( "mytable", "id" );
 $res[] = $db->query( "INSERT INTO mytable (id,field1,field2) VALUES ('$nextid','$value1','$value2')" );
 Db::finish( $res, $db);
}

Update

function UpdateRecord( $id, $value1, $value2 )
{
 $db =& Db::globaldb();
 $db->begin();
 $db->lock( "mytable" );
 $res[] = $db->query( "UPDATE mytable SET field1='$value1',field2='$value2' WHERE id='$id' " );
 Db::finish( $res, $db);
}