På nuværende tidspunkt ser min klasse således ud
<?php
/**
* Include libraries
*/
require_once ('config.php');
/**
* This class contains functions for handling mysql data
*
* @author Martin Askjær Kristensen
* @copyright 2008
* @package MySQL
* @version 1.0
*/
class MySQL
{
/**
* Private variables
*/
private $conn;
/**
* Constructor
*
* @param string hostname hostname for mysql server
* @param string username username for mysql server
* @param string password password for mysql server
* @param string database database which contains your tables
*/
public function __construct($db_hostname = DB_HOST, $db_username = DB_USER, $password = DB_PASS, $database = DB_DATA)
{
$conn = @mysql_connect($hostname, $username, $password);
if($this->isConnected())
@mysql_select_db($database, $this->conn);
}
private function isConnected()
{
if($this->conn)
return true;
else
return false;
}
/**
* Closes the mysql connection
*/
public function close()
{
if($this->isConnected())
{
@mysql_close($this->conn);
}
}
/**
* Counts the rows for the query
*
* @param string sql The sql sentence you want to execute on the mysql server
*/
public function countRows($sql)
{
if($this->isConnected())
{
$num = @mysql_num_rows($sql);
return $num;
}
}
/**
* Fetches the dataarray from the query
*
* @param string sql The sql sentence you want to execute on the mysql server
*/
public function fetchArray($sql)
{
if($this->isConnected())
{
$array = @mysql_fetch_array($sql);
return $array;
}
}
/**
* Query executes the sql sentence on the server
*
* @param string sql The sql sentence you want to execute on the mysql server
*/
public function query($sql)
{
if(!$this->isConnected())
{
if(get_magic_quotes_gpc())
stripslashes($sql);
$sql = @ mysql_real_escape_string($sql, $this->conn);
$query = @mysql_query($sql);
return $query;
}
}
}
?>