id = $id; $this->mode = $mode; $this->size = mysql_num_rows($this->id); } function ¤t() { return $this->current; } function hasNext() { return ($this->row + 1 < $this->size) ? TRUE : FALSE; } function key() { return $this->row; } function next() { $ret = $this->hasNext(); if ($ret) { $this->current = mysql_fetch_array($this->id, $this->mode); $this->row++; } return $ret; } function free() { return mysql_free_result($this->id); } function numRows() { return $this->size; } function reset() { if ($this->row >= 0) mysql_data_seek($this->id, 0); $this->row = -1; return TRUE; } } class MysqlStatement extends FADatabaseStatement { //Use the generic one } class MysqlConnection extends FADatabaseConnection { var $_link; var $_num_queries = 0; function MysqlConnection() { parent::FADatabaseConnection(); if(!extension_loaded('mysql')) trigger_error("The MySQL extension is not loaded.", E_USER_ERROR); define('DBA_NUM', MYSQL_NUM); define('DBA_ASSOC', MYSQL_ASSOC); } function affectedRows() { return mysql_affected_rows($this->_link); } function connect($info) { $ret = TRUE; if (!isset($info['server']) || !isset($info['user']) || !isset($info['pass']) || !isset($info['database'])) { trigger_error("Missing required connection information.", E_USER_ERROR); $ret = FALSE; } if ($ret) { $link = mysql_pconnect($info['server'], $info['user'], $info['pass']); if ($link == FALSE) { trigger_error("Unable to connect to the database", E_USER_ERROR); $ret = FALSE; } else if (!@mysql_select_db($info['database'], $link)) { trigger_error("Unable to select the database", E_USER_ERROR); $ret = FALSE; } $this->_link = $link; } return $ret; } function executeUpdate($stmt) { $start = microtime(); if (!$this->isValid()) trigger_error("Error: Not connected", E_USER_ERROR); $args = func_get_args(); if (func_num_args() == 2 && is_array($args[1])) { $new_args = $args[1]; $args = array($args[0]); foreach ($new_args as $key => $value) { $args[$key + 1] = $value; } } if (count($args) > 1) { $stmt = &new FABasicDatabaseStatement($stmt, $this); for ($i = 1; $i < count($args); $i++) { $stmt->set($i, $args[$i]); } $stmt = $stmt->getSql(); } $result = @mysql_query($stmt, $this->_link); if ($result == FALSE) trigger_error("Invalid query: ". mysql_error($this->_link), E_USER_ERROR); $this->notifyAll(new FADatabaseQueryEvent($stmt, $this->affectedRows(), microtime_diff($start, microtime()))); $this->_num_queries++; return FALSE; } function executeQuery($stmt) { if (!$this->isValid()) trigger_error("Error: Not connected", E_USER_ERROR); $args = func_get_args(); if (func_num_args() == 2 && is_array($args[1])) { $new_args = $args[1]; $args = array($args[0]); foreach ($new_args as $key => $value) { $args[$key + 1] = $value; } } if (count($args) > 1) { $stmt = &new FABasicDatabaseStatement($stmt, $this); for ($i = 1; $i < count($args); $i++) { $stmt->set($i, $args[$i]); } $stmt = $stmt->getSql(); } //echo $stmt .'
'; //die( $stmt); $result = mysql_query($stmt, $this->_link); if (!is_resource($result)) { if (mysql_errno($this->_link) == 0) { trigger_error("Invalid query: Called executeQuery on an update", E_USER_NOTICE); } else { trigger_error("Invalid query: ".mysql_error($this->_link), E_USER_ERROR); } return $result; } $event = &new FADatabaseQueryEvent($stmt, mysql_num_rows($result), microtime_diff($start, microtime())); $this->notifyAll($event); /* Increment the number of queries */ $this->_num_queries++; $result = &new MysqlResultIterator($result, DBA_ASSOC); return $result; } function getInsertId() { /* Increment the number of queries */ return mysql_insert_id($this->_link); } function isValid() { return (bool)$this->_link; } function &prepareStatement($sql) { $stmt = &new MysqlStatement($sql, $this); return $stmt; } function quote($value) { return mysql_escape_string($value); } } ?>