I created this very basic and simple PHP class. Ive used it in a few of my projects - its nothing too special but does allow me to use a more OOP approach to handling databases. You are welcome to use it as you wish in your own projects or modify it to suit your needs.
< ?php
class mysql
{
function Connect($dbserver, $dbuser, $dbpass)
{
mysql_connect($dbserver, $dbuser, $dbpass) or die ("Cannot connect to database server!");
}
function Select($dbname)
{
mysql_select_db($dbname) or die ("Cannot select database!");
}
function Query($sql)
{
$result = mysql_query($sql) or die ("Cant execute query " . mysql_error());
return $result;
}
function NumRows($result)
{
$count = mysql_num_rows($result);
return $count;
}
function FetchArray($result)
{
$array = mysql_fetch_array($result);
return $array;
}
}
?>




Leave a reply