'MASKPRO MySQL driver', 'ver' => '0.2', 'author' => 'Emiliano `AlberT` Gabrielli', 'authoremail' => 'AlberT@SuperAlberT.it', 'authorurl' => 'www.SuperAlberT.it', 'creationdate' => '05/09/2005', 'note' => 'This driver does not implement Transactions', 'copyright' => 'Copyright (C) 2005 Emiliano Gabrielli', ); } /** * Makes DB connection * * @param $host string optional, defaults to 'localhost' * @param $port string optional, defaults to '3306' * @param $username string optional, defaults to '' * @param $password string optional, defaults to '' * @param $dbname string optional, defaults to the value of $username * @param $params string not used in this driver * * @return boolean TRUE on success, FALSE otherwise */ function Connect($host='localhost', $port='3306', $username='', $password='', $dbname='', $params='') { if ($port!='3306') { $host .= ":{$port} "; } if (!empty($username) && empty($dbname)) { $dbname = $username; } $this->iDB = @ mysql_connect($host, $username, $password); if (!$this->iDB || !mysql_select_db($dbname, $this->iDB)) { $this->iLastErrorMsg = mysql_error(); $this->iLastErrorCode = mysql_errno(); return FALSE; } /** FIXME! * we should change the API in order to return the DB handler instead of TRUE! */ return TRUE; } /** * Makes a DB query * * @param $query string, the query to be executed * @return boolean, TRUE on success, FALSE otherwise */ function Query($query) { /** FIXME: are we sure it is always what the user wants? * if($this->iResult) @ mysql_free_result($this->iResult); */ if(! ($this->iResult = @ mysql_query($this->iDB, $query)) ){ $this->iLastErrorMsg = mysql_error($this->iDB); $this->iLastErrorCode = mysql_errno($this->iDB); return FALSE; } return TRUE; } /** * Returns a row from the current resultset * * @return mixed the requested row, FALSE on failure or no row available */ function FetchRow() { if(!$this->iResult) return FALSE; $f = $this->_iFetchFunc; return $f($this->iResult); } /** * Returns the entire resultset * * @return array, the resultset array or FALSE on failure */ function FetchAllRow() { if(!$this->iResult) return FALSE; $f = $this->_iFetchFunc; while (FALSE !== $ret[] = @ $f($this->iResult)); return $ret; } /** * Returns the number of rows the last UPDATE DELETE or INSERT query involved * * @return integer, the number of rows or FALSE on error */ function AffectedRows() { $ret = @ mysql_affected_rows($this->iResult); return ($ret==-1) ? FALSE : $ret; } /** * Returns the code of the last error occurred * * @return integer, the error code */ function GetLastErrorCode() { return $this->iLastErrorCode; } /** * Returns the message relative to the last error occurred * * @return string the error message */ function GetLastErrorMessage() { return $this->iLastErrorMsg; } /** * Closes the actual DB connection * * @return boolean TRUE on success, FALSE on failure */ function Close() { return @ mysql_close($this->iDB); } /** * Gets the DB connection identifier * * @return resource, the connection ID */ function GetInstance() { return $this->iDB; } /** * Sets the fetch mode (FETCH_ASSOCIATIVE or FETCH_INDEX) * * @param $aMode integer, the fetch mode to be selected * @return boolean, TRUE */ function SetFetchMode($aMode) { $this->iFetchMode = $aMode; $this->_iFetchFunc = ($this->iFetchMode===FETCH_INDEX) ? 'mysql_fetch_row' : 'mysql_fetch_assoc'; return TRUE; } /** * Gets the actual fetch mode * * @return FETCH_ASSOCIATIVE or FETCH_INDEX */ function GetFetchMode() { return $this->iFetchMode; } /** * Performs a safe escape of a string to be usend as parameter in a MySQL query * * @param $s string, the string to be escaped * @return mixed, the escaped string or FALSE on failure */ function QuoteString($s) { if (get_magic_quotes_gpc()) { $s = stripslashes($s); } return @ mysql_real_escape_string($s, $this->iDB); } /** * Not implemented in this version of MySQL * * @return boolean always FALSE */ function Commit() { return FALSE; } /** * Not implemented in this version of MySQL * * @return boolean always FALSE */ function Rollback() { return FALSE; } /** * Sets autocommit mode, as this version of MySQL does not support * transactions it is forced to FALSE * * @param $aMode the selected mode * @return boolean, always FALSE * @use: */ function SetAutoCommit($aMode) { return $this->iAutoCommit = FALSE; } /** * Gets the actual autocommit mode * * @return boolean, TRUE if enabled, FALSE otherwise */ function GetAutoCommit() { return $this->iAutoCommit; } } ?>