public
Created

PHP MySQL handler Class

  • Download Gist
dbMySQL.php
PHP
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76
<?php
class DbMySQL {
private $host = DB_HOST;
private $user = DB_USER;
private $password = DB_PASSWORD;
private $database = DB_DATABASE;
private $linkId = null;
function connect () {
if ($this->linkId == 0)
{
$this->linkId = mysql_connect($this->host, $this->user, $this->password);
$selectResult = mysql_select_db($this->database, $this->linkId);
}
}
function close() {
if($this->linkId != 0)
{
$this->cleanResults();
@mysql_close();
$this->linkId = 0;
}
}
function cleanResults() {
if($this->queryId != 0){
@mysql_free_result($this->queryId);
}
}
function query($queryString) {
$this->connect();
$this->queryId = mysql_query($queryString, $this->linkId);
$this->row = 0;
$this->errno = mysql_errno();
$this->error = mysql_error();
if (!$this->queryId)
{
//$this->writeLog($this->error);
echo $queryString;
$this->error = mysql_error();
echo $this->error;
return false;
}
return $this->queryId;
}
function getRecords($flag = MYSQL_ASSOC) {
if ($this->queryId == 0) {
return false;
}
while($row = $this->nextRecord($flag))
$records[] = $row;
return $records;
}
function nextRecord ($flag = MYSQL_ASSOC) {
$this->record = mysql_fetch_array($this->queryId, $flag);
$this->row += 1;
$this->errno = mysql_errno();
$this->error = mysql_error();
$status = is_array($this->record);
if (!$status)
{
mysql_free_result($this->queryId);
$this->queryId = 0;
}
return $this->record;
}
function lastInsertId() {
return mysql_insert_id($this->linkId);
}
}
?>

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.