DB_Access.inc

 


every time you issue a "new DB_Sql" you are forcing it to connect to the
database again, which can really slow things down. Of all the things we
do in PHP, connecting to the DB is one of the slowest and most resource
intensive.

I have rebuild the DB_Access script to check if a connection
already exists... meaning a new one isn't necessary, and I think MySQL/PHP
might to the same. But, I cannot avoid trying to reconnect if you use a
"new DB_Sql" for each query.

 

require_once 'DB_Access.inc'; 
$db = new DB_Sql( parameters ); 
$q1 = $db->query ( "select * from table" ); 
   $q2 = $db->query ( "select * from anothertable " ); 
while ( $db->next_record ( $q1 ) ) 
   { 
   $rs = $db->Record; 
   } 
while ( $db->next_record ( $q2 ) ) 
   { 
   $rs = $db->Record; 
   } 

That will make for better scripts. I know it's more than you want to do
right now, so don't do it now, just start writing that way, and slowly
convert old pages to that. Eventually it will be all caught up. It will
help keep the load on the machine down and make stronger scripts.

Better

This isn't tested, but this is the gist:

$db = new DB_Sql($databasedetails);
   $Annotations = $db->query ( ... );
if($db->num_rows($Annotations))
{
   while($rs = $db->rs($Annotations))
   {
   	$vUserAnnotationID = $rs["UserAnnotationID"];
   	/* or just use $rs['UserAnnotationID'] */
   	if ( $rs['UserAnnotationID'] == 'something' )
   	{
   		# then do this
   	}
  }
}
 

 

Referencing the class

ln -s /home/hspallek/spallek.net/inc/DB_Access.inc ./