Thanks for the suggestions NogDog, much appreciated. I've been working on it and here is an updated version.
<?php
/*
Author : Mathew Davies
Creation : Friday, May 19th 2006
Contact : leveldesign.info@gmail.com
Example Usage :
# // Include the file into your application.
# include('mysql.conf.php');
#
# // Initate a new MySQL class.
# $mysql = new MySQL();
#
# // Lets set the MySQL server parameters.
# $mysql->setServer ('localhost'); // MySQL server address.
# $mysql->setUsername ('root'); // Username used to login to MySQL.
# $mysql->setPassword ('admin'); // Password used to login to MySQL
# $mysql->setDatabase ('levelde_core'); // The database you want to work with.
#
# // Connect to the MySQL with the parameters set as above.
# $mysq->connect();
#
# // Alternative way of connecting to the MySQL server.
# $mysql->connect('server'.'username'.'password');
#
# // Select the database ready for use.
# $mysql->database();
#
# // Alternative way of selecting the database
# $mysql->database('database');
The MySQL is now ready to use, below you will find more information on the different functions
this class has to offer.
// This will execute the query inbetween the brackets. Protection against SQL injections is already done
// within the function.
# $mysql->query('SELECT * FROM examples');
// Fetches data from the last used query. MySQL data is fetched using the mysql_fetch_array(); function.
// Here is the correct way to use the function
# $levelde_news = $mysql->query('SELECT * FROM levelde_news');
#
# while ($row = $mysql->fetch($levelde_news)) {
# $result[] = $row;
# $smarty->assign('news', $result);
# }
*/
class MySQL {
private $server;
private $username;
private $password;
private $database;
private $connection_handle;
private $database_handle;
private $query;
private $result;
function setServer ($server) {
$this->server = $server;
}
function setUsername($username) {
$this->username = $username;
}
function setPassword($password) {
$this->password = $password;
}
function setDatabase($database) {
$this->database = $database;
}
function connect ($server = NULL, $username = NULL, $password = NULL) {
if(!$server == NULL && !$username = NULL && !$password == NULL) {
$this->server = $server;
$this->username = $username;
$this->password = $password;
}
$this->connection_handle = @mysql_connect($this->server, $this->username, $this->password);
if (!$this->connection_handle) {
$this->error();
}
}
function database ($database = NULL) {
if (!$database == NULL) {
$this->database = $database;
}
$this->database_handle = @mysql_select_db($this->database, $this->connection_handle);
if (!$this->database_handle) {
$this->error();
}
}
function query ($query = NULL) {
if (!$query == NULL) {
$this->query = $query;
}
$this->result = mysql_query($this->query, $this->connection_handle);
}
function fetch ($result = NULL) {
if(!$result == NULL) {
$this->result = $result;
}
$row = mysql_fetch_array($this->result);
return $row;
}
function error () {
die ("Error Code : " . mysql_errno() . " <br> Error Message : " . mysql_error());
if ($this->connection_handle) {
mysql_close($this->connection_handle);
}
}
function close () {
if ($this->connection_handle) mysql_close($this->connection_handle);
}
}
?>
I shall implement your ideas.
Kind Regards,
-Matt