| | |
| | | // | Author: Lukas Smith <smith@pooteeweet.org> | |
| | | // +----------------------------------------------------------------------+ |
| | | // |
| | | // $Id: mysqli.php,v 1.188 2008/03/13 03:31:55 afz Exp $ |
| | | // $Id: mysqli.php 292715 2009-12-28 14:06:34Z quipo $ |
| | | // |
| | | |
| | | /** |
| | |
| | | $native_code = @mysqli_connect_errno(); |
| | | $native_msg = @mysqli_connect_error(); |
| | | } |
| | | if (is_null($error)) { |
| | | if (null === $error) { |
| | | static $ecode_map; |
| | | if (empty($ecode_map)) { |
| | | $ecode_map = array( |
| | |
| | | { |
| | | $this->debug('Starting transaction/savepoint', __FUNCTION__, array('is_manip' => true, 'savepoint' => $savepoint)); |
| | | $this->_getServerCapabilities(); |
| | | if (!is_null($savepoint)) { |
| | | if (null !== $savepoint) { |
| | | if (!$this->supports('savepoints')) { |
| | | return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, |
| | | 'savepoints are not supported', __FUNCTION__); |
| | |
| | | } |
| | | $query = 'SAVEPOINT '.$savepoint; |
| | | return $this->_doQuery($query, true); |
| | | } elseif ($this->in_transaction) { |
| | | } |
| | | if ($this->in_transaction) { |
| | | return MDB2_OK; //nothing to do |
| | | } |
| | | $query = $this->start_transaction ? 'START TRANSACTION' : 'SET AUTOCOMMIT = 1'; |
| | | $query = $this->start_transaction ? 'START TRANSACTION' : 'SET AUTOCOMMIT = 0'; |
| | | $result =& $this->_doQuery($query, true); |
| | | if (PEAR::isError($result)) { |
| | | return $result; |
| | |
| | | return $this->raiseError(MDB2_ERROR_INVALID, null, null, |
| | | 'commit/release savepoint cannot be done changes are auto committed', __FUNCTION__); |
| | | } |
| | | if (!is_null($savepoint)) { |
| | | if (null !== $savepoint) { |
| | | if (!$this->supports('savepoints')) { |
| | | return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, |
| | | 'savepoints are not supported', __FUNCTION__); |
| | |
| | | return $result; |
| | | } |
| | | if (!$this->start_transaction) { |
| | | $query = 'SET AUTOCOMMIT = 0'; |
| | | $query = 'SET AUTOCOMMIT = 1'; |
| | | $result =& $this->_doQuery($query, true); |
| | | if (PEAR::isError($result)) { |
| | | return $result; |
| | |
| | | return $this->raiseError(MDB2_ERROR_INVALID, null, null, |
| | | 'rollback cannot be done changes are auto committed', __FUNCTION__); |
| | | } |
| | | if (!is_null($savepoint)) { |
| | | if (null !== $savepoint) { |
| | | if (!$this->supports('savepoints')) { |
| | | return $this->raiseError(MDB2_ERROR_UNSUPPORTED, null, null, |
| | | 'savepoints are not supported', __FUNCTION__); |
| | |
| | | return $result; |
| | | } |
| | | if (!$this->start_transaction) { |
| | | $query = 'SET AUTOCOMMIT = 0'; |
| | | $query = 'SET AUTOCOMMIT = 1'; |
| | | $result =& $this->_doQuery($query, true); |
| | | if (PEAR::isError($result)) { |
| | | return $result; |
| | |
| | | */ |
| | | function setCharset($charset, $connection = null) |
| | | { |
| | | if (is_null($connection)) { |
| | | if (null === $connection) { |
| | | $connection = $this->getConnection(); |
| | | if (PEAR::isError($connection)) { |
| | | return $connection; |
| | |
| | | ((50000 <= $client_info) && (50006 > $client_info))) |
| | | ) { |
| | | $query = "SET NAMES '".mysqli_real_escape_string($connection, $charset)."'"; |
| | | if (!is_null($collation)) { |
| | | if (null !== $collation) { |
| | | $query .= " COLLATE '".mysqli_real_escape_string($connection, $collation)."'"; |
| | | } |
| | | return $this->_doQuery($query, true, $connection); |
| | |
| | | } |
| | | |
| | | if ($force) { |
| | | @mysqli_close($this->connection); |
| | | $ok = @mysqli_close($this->connection); |
| | | if (!$ok) { |
| | | return $this->raiseError(MDB2_ERROR_DISCONNECT_FAILED, |
| | | null, null, null, __FUNCTION__); |
| | | } |
| | | } |
| | | } else { |
| | | return false; |
| | | } |
| | | return parent::disconnect($force); |
| | | } |
| | |
| | | return $result; |
| | | } |
| | | |
| | | if (is_null($connection)) { |
| | | if (null === $connection) { |
| | | $connection = $this->getConnection(); |
| | | if (PEAR::isError($connection)) { |
| | | return $connection; |
| | | } |
| | | } |
| | | if (is_null($database_name)) { |
| | | if (null === $database_name) { |
| | | $database_name = $this->database_name; |
| | | } |
| | | |
| | |
| | | $result = mysqli_query($connection, $query); |
| | | } |
| | | |
| | | if (!$result) { |
| | | if (!$result && 0 !== mysqli_errno($connection)) { |
| | | $err =& $this->raiseError(null, null, null, |
| | | 'Could not execute statement', __FUNCTION__); |
| | | return $err; |
| | |
| | | */ |
| | | function _affectedRows($connection, $result = null) |
| | | { |
| | | if (is_null($connection)) { |
| | | if (null === $connection) { |
| | | $connection = $this->getConnection(); |
| | | if (PEAR::isError($connection)) { |
| | | return $connection; |
| | |
| | | $this->supported['prepared_statements'] = true; |
| | | } |
| | | |
| | | // SAVEPOINTS were introduced in MySQL 4.0.14 and 4.1.1 (InnoDB) |
| | | // SAVEPOINTs were introduced in MySQL 4.0.14 and 4.1.1 (InnoDB) |
| | | if (version_compare($server_version, '4.1.0', '>=')) { |
| | | if (version_compare($server_version, '4.1.1', '<')) { |
| | | $this->supported['savepoints'] = false; |
| | |
| | | function _skipUserDefinedVariable($query, $position) |
| | | { |
| | | $found = strpos(strrev(substr($query, 0, $position)), '@'); |
| | | if ($found === false) { |
| | | if (false === $found) { |
| | | return $position; |
| | | } |
| | | $pos = strlen($query) - strlen(substr($query, $position)) - $found - 1; |
| | |
| | | */ |
| | | function &prepare($query, $types = null, $result_types = null, $lobs = array()) |
| | | { |
| | | // connect to get server capabilities (http://pear.php.net/bugs/16147) |
| | | $connection = $this->getConnection(); |
| | | if (PEAR::isError($connection)) { |
| | | return $connection; |
| | | } |
| | | |
| | | if ($this->options['emulate_prepared'] |
| | | || $this->supported['prepared_statements'] !== true |
| | | ) { |
| | |
| | | } else { |
| | | break; |
| | | } |
| | | if (is_null($placeholder_type)) { |
| | | if (null === $placeholder_type) { |
| | | $placeholder_type_guess = $query[$p_position]; |
| | | } |
| | | |
| | |
| | | } |
| | | |
| | | if ($query[$position] == $placeholder_type_guess) { |
| | | if (is_null($placeholder_type)) { |
| | | if (null === $placeholder_type) { |
| | | $placeholder_type = $query[$p_position]; |
| | | $question = $colon = $placeholder_type; |
| | | } |
| | |
| | | } else { |
| | | $position = $p_position; |
| | | } |
| | | } |
| | | $connection = $this->getConnection(); |
| | | if (PEAR::isError($connection)) { |
| | | return $connection; |
| | | } |
| | | |
| | | if (!$is_manip) { |
| | |
| | | /** |
| | | * Execute a SQL REPLACE query. A REPLACE query is identical to a INSERT |
| | | * query, except that if there is already a row in the table with the same |
| | | * key field values, the REPLACE query just updates its values instead of |
| | | * inserting a new row. |
| | | * key field values, the old row is deleted before the new row is inserted. |
| | | * |
| | | * The REPLACE type of query does not make part of the SQL standards. Since |
| | | * practically only MySQL implements it natively, this type of query is |
| | |
| | | * |
| | | * Default: 0 |
| | | * |
| | | * @see http://dev.mysql.com/doc/refman/5.0/en/replace.html |
| | | * @return mixed MDB2_OK on success, a MDB2 error on failure |
| | | */ |
| | | function replace($table, $fields) |
| | |
| | | */ |
| | | function &fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT, $rownum = null) |
| | | { |
| | | if (!is_null($rownum)) { |
| | | if (null !== $rownum) { |
| | | $seek = $this->seek($rownum); |
| | | if (PEAR::isError($seek)) { |
| | | return $seek; |
| | |
| | | } |
| | | |
| | | if (!$row) { |
| | | if ($this->result === false) { |
| | | if (false === $this->result) { |
| | | $err =& $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, |
| | | 'resultset has already been freed', __FUNCTION__); |
| | | return $err; |
| | |
| | | if ($object_class == 'stdClass') { |
| | | $row = (object) $row; |
| | | } else { |
| | | $row = new $object_class($row); |
| | | $rowObj = new $object_class($row); |
| | | $row = $rowObj; |
| | | } |
| | | } |
| | | ++$this->rownum; |
| | |
| | | function numCols() |
| | | { |
| | | $cols = @mysqli_num_fields($this->result); |
| | | if (is_null($cols)) { |
| | | if ($this->result === false) { |
| | | if (null === $cols) { |
| | | if (false === $this->result) { |
| | | return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, |
| | | 'resultset has already been freed', __FUNCTION__); |
| | | } elseif (is_null($this->result)) { |
| | | } |
| | | if (null === $this->result) { |
| | | return count($this->types); |
| | | } |
| | | return $this->db->raiseError(null, null, null, |
| | |
| | | */ |
| | | function free() |
| | | { |
| | | if (is_object($this->result) && $this->db->connection) { |
| | | $free = @mysqli_free_result($this->result); |
| | | if ($free === false) { |
| | | return $this->db->raiseError(null, null, null, |
| | | 'Could not free result', __FUNCTION__); |
| | | do { |
| | | if (is_object($this->result) && $this->db->connection) { |
| | | $free = @mysqli_free_result($this->result); |
| | | if (false === $free) { |
| | | return $this->db->raiseError(null, null, null, |
| | | 'Could not free result', __FUNCTION__); |
| | | } |
| | | } |
| | | } |
| | | } while ($this->result = $this->nextResult()); |
| | | |
| | | $this->result = false; |
| | | return MDB2_OK; |
| | | } |
| | |
| | | function seek($rownum = 0) |
| | | { |
| | | if ($this->rownum != ($rownum - 1) && !@mysqli_data_seek($this->result, $rownum)) { |
| | | if ($this->result === false) { |
| | | if (false === $this->result) { |
| | | return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, |
| | | 'resultset has already been freed', __FUNCTION__); |
| | | } elseif (is_null($this->result)) { |
| | | } |
| | | if (null === $this->result) { |
| | | return MDB2_OK; |
| | | } |
| | | return $this->db->raiseError(MDB2_ERROR_INVALID, null, null, |
| | |
| | | function numRows() |
| | | { |
| | | $rows = @mysqli_num_rows($this->result); |
| | | if (is_null($rows)) { |
| | | if ($this->result === false) { |
| | | if (null === $rows) { |
| | | if (false === $this->result) { |
| | | return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null, |
| | | 'resultset has already been freed', __FUNCTION__); |
| | | } elseif (is_null($this->result)) { |
| | | } |
| | | if (null === $this->result) { |
| | | return 0; |
| | | } |
| | | return $this->db->raiseError(null, null, null, |
| | |
| | | * |
| | | * @param mixed $result_class string which specifies which result class to use |
| | | * @param mixed $result_wrap_class string which specifies which class to wrap results in |
| | | * @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure |
| | | * |
| | | * @return mixed MDB2_Result or integer (affected rows) on success, |
| | | * a MDB2 error on failure |
| | | * @access private |
| | | */ |
| | | function &_execute($result_class = true, $result_wrap_class = false) |
| | | { |
| | | if (is_null($this->statement)) { |
| | | if (null === $this->statement) { |
| | | $result =& parent::_execute($result_class, $result_wrap_class); |
| | | return $result; |
| | | } |
| | |
| | | $query.= ' USING @'.implode(', @', array_values($this->positions)); |
| | | } else { |
| | | $result = @call_user_func_array('mysqli_stmt_bind_param', $parameters); |
| | | if ($result === false) { |
| | | if (false === $result) { |
| | | $err =& $this->db->raiseError(null, null, null, |
| | | 'Unable to bind parameters', __FUNCTION__); |
| | | return $err; |
| | |
| | | */ |
| | | function free() |
| | | { |
| | | if (is_null($this->positions)) { |
| | | if (null === $this->positions) { |
| | | return $this->db->raiseError(MDB2_ERROR, null, null, |
| | | 'Prepared statement has already been freed', __FUNCTION__); |
| | | } |
| | |
| | | $result = $this->db->raiseError(null, null, null, |
| | | 'Could not free statement', __FUNCTION__); |
| | | } |
| | | } elseif (!is_null($this->statement)) { |
| | | } elseif (null !== $this->statement) { |
| | | $connection = $this->db->getConnection(); |
| | | if (PEAR::isError($connection)) { |
| | | return $connection; |