PHP & MySQL Class

This was posted on Tuesday, April 10th, 2007 and is filed under Web dev. You can follow any responses to this entry through the RSS 2.0 feed. You are also welcome to trackback from your own site.

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

Bookmark on digg
Bookmark on del.icio.us
Archives
Related Posts
Links
        RSS Feed