Tuesday, March 24, 2009

PHP Advanced Database Class

i found this class very useful for php mysql development. you can use this class to sped up your php development.

usualy if you want to make a query to a table in your database you need to:

  1. make the connection to database
  2. add the query (eg. $sql = select * from table)
  3. add the ($result = mysql_query($sql)) line
  4. then (while($row = mysq_fetch_array($result)){….})

now when you use this class, you do it like this:

 

// Include the class:
include("db.class.php");

// Open the base (construct the object):
$db = new DB($base, $server, $user, $pass);

// Commonly, you can copy/paste this code for one query at a time:
$db->query("SELECT * FROM People");
while ($line = $db->fetchNextObject()) {
  use($line->aField);
}

although you can use $db->query("SELECT * FROM People",true); this will enable debug mode, so if there is an error you will got a help on your error.

for more information please visit the main site

you can download the class from here

No comments: