_message = $message; } function getMessage() { return $this->_message; } } class MysqliResultIterator extends FADatabaseResult { var $id; var $mode; var $row = -1; var $current; var $size; function MysqliResultIterator($id, $mode) { $this->id = $id; $this->mode = $mode; $this->size = mysqli_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 = mysqli_fetch_array($this->id, $this->mode); $this->row++; } return $ret; } function free() { return mysqli_free_result($this->id); } function numRows() { return $this->size; } function reset() { if ($this->row >= 0) mysqli_data_seek($this->id, 0); $this->row = -1; return TRUE; } } class MysqliStatement extends FABasicDatabaseStatement { } class MysqliConnection extends FADatabaseConnection { var $_link; var $_dispatcher; function MysqliConnection() { if(!extension_loaded('mysqli')) trigger_error("The MySQL Improved (mysqli) extension is not loaded.", E_USER_ERROR); define('DBA_NUM', MYSQLI_NUM); define('DBA_ASSOC', MYSQLI_ASSOC); $this->_dispatcher = &new FADispatcher; } function addObserver(&$observer) { $this->_dispatcher->addObserver($observer); } function affectedRows() { if (!$this->isValid()) trigger_error("Error: Not connected", E_USER_ERROR); return mysqli_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 = @mysqli_connect($info['server'], $info['user'], $info['pass'], $info['database']); if ($link == FALSE) { trigger_error("Unable to connect to the database", E_USER_ERROR); $ret = FALSE; } $this->_link = $link; } return $ret; } function &createStatement($sql) { $stmt = &new MysqliStatement($sql, $this); return $stmt; } function executeUpdate($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(); } //die( $stmt); $result = @mysqli_real_query($this->_link, $stmt); $this->notifyAll(new MysqliEvent($stmt)); if ($result == FALSE) trigger_error("Invalid query: ". mysqli_error($this->_link), E_USER_ERROR); $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(); } $result = @mysqli_query($this->_link, $stmt); $this->notifyAll(new MysqliEvent($stmt)); if (!$result) { if (mysqli_errno($this->_link) == 0) trigger_error("Invalid query: Called executeQuery on an update", E_USER_NOTICE); trigger_error("Invalid query: ".mysqli_error($this->_link), E_USER_ERROR); return FALSE; } /* Increment the number of queries */ $this->num_queries++; $result = &new MysqliResultIterator($result, DBA_ASSOC); return $result; } function getInsertId() { if (!$this->isValid()) trigger_error("Error: Not connected", E_USER_ERROR); return mysqli_insert_id($this->_link); } function isValid() { return (bool)$this->_link; } function notifyAll(&$event) { $this->_dispatcher->notifyAll($event); } function &prepareStatement($stmt) { if (!$this->isValid()) trigger_error("Error: Not connected", E_USER_ERROR); return new MysqliStatement($stmt, $this); } function quote($value) { if (!$this->isValid()) trigger_error("Error: Not connected", E_USER_ERROR); return mysqli_escape_string($this->_link, $value); } } ?>