Admin
13/06/2009, 19:08
<?php
/*================================================= ===========================*\
|| ################################################## ######################## ||
|| # Simple Database & Query Handling # ||
|| # ---------------------------------------------------------------------- # ||
|| # (C) Copyright Y2K Software s.a.s. 2009 - All Rights Reserved. # ||
|| # This file may not be redistributed in whole or significant part. # ||
|| ################################################## ######################## ||
\*================================================ ============================*/
/**
* @author Y2K Software
* @copyright (C) Copyright Y2K Software 2009 - All Rights Reserved
* @version 1.0.0
* @link www.pagerobot.com
*/
class db_mysql
{
var $host = 'localhost';
var $port = 3306;
var $user = 'root';
var $pass = '';
var $name = '';
var $error = '';
var $errno = 0;
var $SQL = '';
/**
* db_mysql::_seterror()
*
* Sets error codes.
*
* @return void
*/
function _seterror()
{
$this->errno = @mysql_errno();
$this->error = @mysql_error();
}
/**
* db_mysql::open()
*
* Opens a database.
*
* @return boolean success
*/
function open()
{
$this->close();
if(!$this->connect())
{
return false;
}
if(!@mysql_select_db($this->name))
{
return false;
}
return true;
}
/**
* db_mysql::connect()
*
* Connects to a database host.
*
* @return boolean success
*/
function connect()
{
$this->close();
if(!@mysql_connect($this->host . ':' . $this->port, $this->user, $this->pass))
{
$this->_seterror();
return false;
}
return true;
}
/**
* db_mysql::close()
*
* Closes a database.
*
* @return boolean success
*/
function close()
{
@mysql_close();
return true;
}
/**
* db_mysql::query_read()
*
* Opens a recordset for read.
*
* @param mixed $SQL
* @return result open recordset
*/
function query_read($SQL)
{
if(!$rss = @mysql_query($SQL))
{
$this->SQL = $SQL;
$this->_seterror();
return false;
}
return $rss;
}
/**
* db_mysql::query_write()
*
* Executes a query.
*
* @param mixed $SQL
* @return boolean success
*/
function query_write($SQL)
{
if(!@mysql_query($SQL))
{
$this->SQL = $SQL;
$this->_seterror();
return false;
}
return true;
}
/**
* db_mysql::free()
*
* Closes a recordset.
*
* @param mixed $rss
* @return boolean success
*/
function free($rss)
{
@mysql_free_result($rss);
return true;
}
/**
* db_mysql::query_first()
*
* Gets the first matching entry of a read query.
* Cleses the recordset.
*
* @param mixed $SQL
* @return result row
*/
function query_first($SQL)
{
if(!$rss = $this->query_read($SQL))
{
return false;
}
if(!$rs = $this->fetch($rss))
{
return false;
}
$this->free($rss);
return $rs;
}
/**
* db_mysql::fetch()
*
* Gets an associative row from a given recordset.
*
* @param mixed $rss
* @return result row
*/
function fetch($rss)
{
if(!$rs = @mysql_fetch_assoc($rss))
{
$this->_seterror();
return false;
}
return $rs;
}
/**
* db_mysql::fetch_row()
*
* Gets a nomerically indexed row from a given recordset.
*
* @param mixed $rss
* @return result row
*/
function fetch_row($rss)
{
if(!$rs = @mysql_fetch_row($rss))
{
$this->_seterror();
return false;
}
return $rs;
}
/**
* db_mysql::escape_string()
*
* Escapes a string for a query.
*
* @param mixed $string
* @return mixed $string
*/
function escape_string($string)
{
return mysql_real_escape_string($string);
}
/**
* db_mysql::rows()
*
* Returns the number of affected rows from the last query.
*
* @param mixed $rss
* @return number of rows
*/
function rows($rss)
{
$n = @mysql_num_rows($rss);
if($n === false)
{
$this->_seterror();
$n = 0;
}
return $n;
}
}
?>
/*================================================= ===========================*\
|| ################################################## ######################## ||
|| # Simple Database & Query Handling # ||
|| # ---------------------------------------------------------------------- # ||
|| # (C) Copyright Y2K Software s.a.s. 2009 - All Rights Reserved. # ||
|| # This file may not be redistributed in whole or significant part. # ||
|| ################################################## ######################## ||
\*================================================ ============================*/
/**
* @author Y2K Software
* @copyright (C) Copyright Y2K Software 2009 - All Rights Reserved
* @version 1.0.0
* @link www.pagerobot.com
*/
class db_mysql
{
var $host = 'localhost';
var $port = 3306;
var $user = 'root';
var $pass = '';
var $name = '';
var $error = '';
var $errno = 0;
var $SQL = '';
/**
* db_mysql::_seterror()
*
* Sets error codes.
*
* @return void
*/
function _seterror()
{
$this->errno = @mysql_errno();
$this->error = @mysql_error();
}
/**
* db_mysql::open()
*
* Opens a database.
*
* @return boolean success
*/
function open()
{
$this->close();
if(!$this->connect())
{
return false;
}
if(!@mysql_select_db($this->name))
{
return false;
}
return true;
}
/**
* db_mysql::connect()
*
* Connects to a database host.
*
* @return boolean success
*/
function connect()
{
$this->close();
if(!@mysql_connect($this->host . ':' . $this->port, $this->user, $this->pass))
{
$this->_seterror();
return false;
}
return true;
}
/**
* db_mysql::close()
*
* Closes a database.
*
* @return boolean success
*/
function close()
{
@mysql_close();
return true;
}
/**
* db_mysql::query_read()
*
* Opens a recordset for read.
*
* @param mixed $SQL
* @return result open recordset
*/
function query_read($SQL)
{
if(!$rss = @mysql_query($SQL))
{
$this->SQL = $SQL;
$this->_seterror();
return false;
}
return $rss;
}
/**
* db_mysql::query_write()
*
* Executes a query.
*
* @param mixed $SQL
* @return boolean success
*/
function query_write($SQL)
{
if(!@mysql_query($SQL))
{
$this->SQL = $SQL;
$this->_seterror();
return false;
}
return true;
}
/**
* db_mysql::free()
*
* Closes a recordset.
*
* @param mixed $rss
* @return boolean success
*/
function free($rss)
{
@mysql_free_result($rss);
return true;
}
/**
* db_mysql::query_first()
*
* Gets the first matching entry of a read query.
* Cleses the recordset.
*
* @param mixed $SQL
* @return result row
*/
function query_first($SQL)
{
if(!$rss = $this->query_read($SQL))
{
return false;
}
if(!$rs = $this->fetch($rss))
{
return false;
}
$this->free($rss);
return $rs;
}
/**
* db_mysql::fetch()
*
* Gets an associative row from a given recordset.
*
* @param mixed $rss
* @return result row
*/
function fetch($rss)
{
if(!$rs = @mysql_fetch_assoc($rss))
{
$this->_seterror();
return false;
}
return $rs;
}
/**
* db_mysql::fetch_row()
*
* Gets a nomerically indexed row from a given recordset.
*
* @param mixed $rss
* @return result row
*/
function fetch_row($rss)
{
if(!$rs = @mysql_fetch_row($rss))
{
$this->_seterror();
return false;
}
return $rs;
}
/**
* db_mysql::escape_string()
*
* Escapes a string for a query.
*
* @param mixed $string
* @return mixed $string
*/
function escape_string($string)
{
return mysql_real_escape_string($string);
}
/**
* db_mysql::rows()
*
* Returns the number of affected rows from the last query.
*
* @param mixed $rss
* @return number of rows
*/
function rows($rss)
{
$n = @mysql_num_rows($rss);
if($n === false)
{
$this->_seterror();
$n = 0;
}
return $n;
}
}
?>