MDB2
[ class tree: MDB2 ] [ index: MDB2 ] [ all elements ]

Source for file mysqli.php

Documentation is available at mysqli.php

  1. <?php
  2. // vim: set et ts=4 sw=4 fdm=marker:
  3. // +----------------------------------------------------------------------+
  4. // | PHP versions 4 and 5                                                 |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1998-2006 Manuel Lemos, Tomas V.V.Cox,                 |
  7. // | Stig. S. Bakken, Lukas Smith                                         |
  8. // | All rights reserved.                                                 |
  9. // +----------------------------------------------------------------------+
  10. // | MDB2 is a merge of PEAR DB and Metabases that provides a unified DB  |
  11. // | API as well as database abstraction for PHP applications.            |
  12. // | This LICENSE is in the BSD license style.                            |
  13. // |                                                                      |
  14. // | Redistribution and use in source and binary forms, with or without   |
  15. // | modification, are permitted provided that the following conditions   |
  16. // | are met:                                                             |
  17. // |                                                                      |
  18. // | Redistributions of source code must retain the above copyright       |
  19. // | notice, this list of conditions and the following disclaimer.        |
  20. // |                                                                      |
  21. // | Redistributions in binary form must reproduce the above copyright    |
  22. // | notice, this list of conditions and the following disclaimer in the  |
  23. // | documentation and/or other materials provided with the distribution. |
  24. // |                                                                      |
  25. // | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken,    |
  26. // | Lukas Smith nor the names of his contributors may be used to endorse |
  27. // | or promote products derived from this software without specific prior|
  28. // | written permission.                                                  |
  29. // |                                                                      |
  30. // | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS  |
  31. // | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT    |
  32. // | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS    |
  33. // | FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE      |
  34. // | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,          |
  35. // | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
  36. // | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|
  37. // |  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED  |
  38. // | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT          |
  39. // | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|
  40. // | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE          |
  41. // | POSSIBILITY OF SUCH DAMAGE.                                          |
  42. // +----------------------------------------------------------------------+
  43. // | Author: Lukas Smith <smith@pooteeweet.org>                           |
  44. // +----------------------------------------------------------------------+
  45. //
  46. // $Id: mysqli.php,v 1.82 2006/04/16 11:55:14 lsmith Exp $
  47. //
  48.  
  49. /**
  50.  * MDB2 MySQL driver
  51.  *
  52.  * @package MDB2
  53.  * @category Database
  54.  * @author  Lukas Smith <smith@pooteeweet.org>
  55.  */
  56. class MDB2_Driver_mysqli extends MDB2_Driver_Common
  57. {
  58.     // {{{ properties
  59.     var $escape_quotes = "\\";
  60.  
  61.     // }}}
  62.     // {{{ constructor
  63.  
  64.     /**
  65.      * Constructor
  66.      */
  67.     function __construct()
  68.     {
  69.         parent::__construct();
  70.  
  71.         $this->phptype 'mysqli';
  72.         $this->dbsyntax 'mysql';
  73.  
  74.         $this->supported['sequences''emulated';
  75.         $this->supported['indexes'= true;
  76.         $this->supported['affected_rows'= true;
  77.         $this->supported['transactions'= false;
  78.         $this->supported['summary_functions'= true;
  79.         $this->supported['order_by_text'= true;
  80.         $this->supported['current_id''emulated';
  81.         $this->supported['limit_queries'= true;
  82.         $this->supported['LOBs'= true;
  83.         $this->supported['replace'= true;
  84.         $this->supported['sub_selects''emulated';
  85.         $this->supported['auto_increment'= true;
  86.         $this->supported['primary_key'= true;
  87.         $this->supported['result_introspection'= true;
  88.  
  89.         $this->options['default_table_type'= null;
  90.         $this->options['multi_query'= false;
  91.     }
  92.  
  93.     // }}}
  94.     // {{{ errorInfo()
  95.  
  96.     /**
  97.      * This method is used to collect information about an error
  98.      *
  99.      * @param integer $error 
  100.      * @return array 
  101.      * @access public
  102.      */
  103.     function errorInfo($error = null)
  104.     {
  105.         if ($this->connection{
  106.             $native_code @mysqli_errno($this->connection);
  107.             $native_msg  @mysqli_error($this->connection);
  108.         else {
  109.             $native_code @mysqli_errno();
  110.             $native_msg  @mysqli_error();
  111.         }
  112.         if (is_null($error)) {
  113.             static $ecode_map;
  114.             if (empty($ecode_map)) {
  115.                 $ecode_map = array(
  116.                     1004 => MDB2_ERROR_CANNOT_CREATE,
  117.                     1005 => MDB2_ERROR_CANNOT_CREATE,
  118.                     1006 => MDB2_ERROR_CANNOT_CREATE,
  119.                     1007 => MDB2_ERROR_ALREADY_EXISTS,
  120.                     1008 => MDB2_ERROR_CANNOT_DROP,
  121.                     1022 => MDB2_ERROR_ALREADY_EXISTS,
  122.                     1044 => MDB2_ERROR_ACCESS_VIOLATION,
  123.                     1046 => MDB2_ERROR_NODBSELECTED,
  124.                     1048 => MDB2_ERROR_CONSTRAINT,
  125.                     1049 => MDB2_ERROR_NOSUCHDB,
  126.                     1050 => MDB2_ERROR_ALREADY_EXISTS,
  127.                     1051 => MDB2_ERROR_NOSUCHTABLE,
  128.                     1054 => MDB2_ERROR_NOSUCHFIELD,
  129.                     1061 => MDB2_ERROR_ALREADY_EXISTS,
  130.                     1062 => MDB2_ERROR_ALREADY_EXISTS,
  131.                     1064 => MDB2_ERROR_SYNTAX,
  132.                     1091 => MDB2_ERROR_NOT_FOUND,
  133.                     1100 => MDB2_ERROR_NOT_LOCKED,
  134.                     1136 => MDB2_ERROR_VALUE_COUNT_ON_ROW,
  135.                     1142 => MDB2_ERROR_ACCESS_VIOLATION,
  136.                     1146 => MDB2_ERROR_NOSUCHTABLE,
  137.                     1216 => MDB2_ERROR_CONSTRAINT,
  138.                     1217 => MDB2_ERROR_CONSTRAINT,
  139.                 );
  140.             }
  141.             if ($this->options['portability'MDB2_PORTABILITY_ERRORS{
  142.                 $ecode_map[1022= MDB2_ERROR_CONSTRAINT;
  143.                 $ecode_map[1048= MDB2_ERROR_CONSTRAINT_NOT_NULL;
  144.                 $ecode_map[1062= MDB2_ERROR_CONSTRAINT;
  145.             else {
  146.                 // Doing this in case mode changes during runtime.
  147.                 $ecode_map[1022= MDB2_ERROR_ALREADY_EXISTS;
  148.                 $ecode_map[1048= MDB2_ERROR_CONSTRAINT;
  149.                 $ecode_map[1062= MDB2_ERROR_ALREADY_EXISTS;
  150.             }
  151.             if (isset($ecode_map[$native_code])) {
  152.                 $error $ecode_map[$native_code];
  153.             }
  154.         }
  155.         return array($error$native_code$native_msg);
  156.     }
  157.  
  158.     // }}}
  159.     // {{{ escape()
  160.  
  161.     /**
  162.      * Quotes a string so it can be safely used in a query. It will quote
  163.      * the text so it can safely be used within a query.
  164.      *
  165.      * @param string $text the input string to quote
  166.      * @return string quoted string
  167.      * @access public
  168.      */
  169.     function escape($text)
  170.     {
  171.         $connection $this->getConnection();
  172.         if (PEAR::isError($connection)) {
  173.             return $connection;
  174.         }
  175.         return @mysqli_escape_string($connection$text);
  176.     }
  177.  
  178.     // }}}
  179.     // {{{ quoteIdentifier()
  180.  
  181.     /**
  182.      * Quote a string so it can be safely used as a table or column name
  183.      *
  184.      * Quoting style depends on which database driver is being used.
  185.      *
  186.      * MySQL can't handle the backtick character (<kbd>`</kbd>) in
  187.      * table or column names.
  188.      *
  189.      * @param string $str  identifier name to be quoted
  190.      * @param bool   $check_option  check the 'quote_identifier' option
  191.      *
  192.      * @return string  quoted identifier string
  193.      *
  194.      * @access public
  195.      */
  196.     function quoteIdentifier($str$check_option = false)
  197.     {
  198.         if ($check_option && !$this->options['quote_identifier']{
  199.             return $str;
  200.         }
  201.         return '`' $str '`';
  202.     }
  203.  
  204.     // }}}
  205.     // {{{ beginTransaction()
  206.  
  207.     /**
  208.      * Start a transaction.
  209.      *
  210.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  211.      * @access public
  212.      */
  213.     function beginTransaction()
  214.     {
  215.         $this->debug('starting transaction''beginTransaction');
  216.         if (!$this->supports('transactions')) {
  217.             return $this->raiseError(MDB2_ERROR_UNSUPPORTEDnullnull,
  218.                 'beginTransaction: transactions are not in use');
  219.         }
  220.         if ($this->in_transaction{
  221.             return MDB2_OK;  //nothing to do
  222.         }
  223.         $result $this->_doQuery('SET AUTOCOMMIT = 0'true);
  224.         if (PEAR::isError($result)) {
  225.             return $result;
  226.         }
  227.         $this->in_transaction = true;
  228.         return MDB2_OK;
  229.     }
  230.  
  231.     // }}}
  232.     // {{{ commit()
  233.  
  234.     /**
  235.      * Commit the database changes done during a transaction that is in
  236.      * progress.
  237.      *
  238.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  239.      * @access public
  240.      */
  241.     function commit()
  242.     {
  243.         $this->debug('commit transaction''commit');
  244.         if (!$this->supports('transactions')) {
  245.             return $this->raiseError(MDB2_ERROR_UNSUPPORTEDnullnull,
  246.                 'commit: transactions are not in use');
  247.         }
  248.         if (!$this->in_transaction{
  249.             return $this->raiseError(MDB2_ERRORnullnull,
  250.                 'commit: transaction changes are being auto committed');
  251.         }
  252.         $result $this->_doQuery('COMMIT'true);
  253.         if (PEAR::isError($result)) {
  254.             return $result;
  255.         }
  256.         $result $this->_doQuery('SET AUTOCOMMIT = 1'true);
  257.         if (PEAR::isError($result)) {
  258.             return $result;
  259.         }
  260.         $this->in_transaction = false;
  261.         return MDB2_OK;
  262.     }
  263.  
  264.     // }}}
  265.     // {{{ rollback()
  266.  
  267.     /**
  268.      * Cancel any database changes done during a transaction that is in
  269.      * progress.
  270.      *
  271.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  272.      * @access public
  273.      */
  274.     function rollback()
  275.     {
  276.         $this->debug('rolling back transaction''rollback');
  277.         if (!$this->supports('transactions')) {
  278.             return $this->raiseError(MDB2_ERROR_UNSUPPORTEDnullnull,
  279.                 'rollback: transactions are not in use');
  280.         }
  281.         if (!$this->in_transaction{
  282.             return $this->raiseError(MDB2_ERRORnullnull,
  283.                 'rollback: transactions can not be rolled back when changes are auto committed');
  284.         }
  285.         $result $this->_doQuery('ROLLBACK'true);
  286.         if (PEAR::isError($result)) {
  287.             return $result;
  288.         }
  289.         $result $this->_doQuery('SET AUTOCOMMIT = 1'true);
  290.         if (PEAR::isError($result)) {
  291.             return $result;
  292.         }
  293.         $this->in_transaction = false;
  294.         return MDB2_OK;
  295.     }
  296.  
  297.     // }}}
  298.     // {{{ connect()
  299.  
  300.     /**
  301.      * Connect to the database
  302.      *
  303.      * @return true on success, MDB2 Error Object on failure
  304.      */
  305.     function connect()
  306.     {
  307.         if (is_object($this->connection)) {
  308.             if (count(array_diff($this->connected_dsn$this->dsn)) == 0{
  309.                 return MDB2_OK;
  310.             }
  311.             $this->connection = 0;
  312.         }
  313.  
  314.         if (!PEAR::loadExtension($this->phptype)) {
  315.             return $this->raiseError(MDB2_ERROR_NOT_FOUNDnullnull,
  316.                 'connect: extension '.$this->phptype.' is not compiled into PHP');
  317.         }
  318.  
  319.         @ini_set('track_errors'true);
  320.         $php_errormsg '';
  321.  
  322.         if ($this->options['ssl']{
  323.             $init @mysqli_init();
  324.             @mysqli_ssl_set(
  325.                 $init,
  326.                 empty($this->dsn['key'])    ? null : $this->dsn['key'],
  327.                 empty($this->dsn['cert'])   ? null : $this->dsn['cert'],
  328.                 empty($this->dsn['ca'])     ? null : $this->dsn['ca'],
  329.                 empty($this->dsn['capath']? null : $this->dsn['capath'],
  330.                 empty($this->dsn['cipher']? null : $this->dsn['cipher']
  331.             );
  332.             if ($connection @mysqli_real_connect(
  333.                     $init,
  334.                     $this->dsn['hostspec'],
  335.                     $this->dsn['username'],
  336.                     $this->dsn['password'],
  337.                     $this->database_name,
  338.                     $this->dsn['port'],
  339.                     $this->dsn['socket']))
  340.             {
  341.                 $connection $init;
  342.             }
  343.         else {
  344.             $connection @mysqli_connect(
  345.                 $this->dsn['hostspec'],
  346.                 $this->dsn['username'],
  347.                 $this->dsn['password'],
  348.                 $this->database_name,
  349.                 $this->dsn['port'],
  350.                 $this->dsn['socket']
  351.             );
  352.         }
  353.  
  354.         @ini_restore('track_errors');
  355.  
  356.         if (!$connection{
  357.             if (($err @mysqli_connect_error()) != ''{
  358.                 return $this->raiseError(MDB2_ERROR_CONNECT_FAILEDnullnull$err);
  359.             else {
  360.                 return $this->raiseError(MDB2_ERROR_CONNECT_FAILEDnullnull$php_errormsg);
  361.             }
  362.         }
  363.  
  364.         if (isset($this->dsn['charset']&& !empty($this->dsn['charset'])
  365.             && !@mysqli_query('SET character_set_client = '.$this->quote($this->dsn['charset']'text')$connection)
  366.         {
  367.             return $this->raiseError(MDB2_ERROR,
  368.                 nullnull'Unable to set client charset: '.$this->dsn['charset']);
  369.         }
  370.  
  371.         $this->connection $connection;
  372.         $this->connected_dsn $this->dsn;
  373.         $this->connected_database_name $this->database_name;
  374.         $this->dbsyntax $this->dsn['dbsyntax'$this->dsn['dbsyntax'$this->phptype;
  375.  
  376.         $this->supported['transactions'= false;
  377.         if ($this->options['default_table_type']{
  378.             switch (strtoupper($this->options['default_table_type'])) {
  379.             case 'BERKELEYDB':
  380.                 $this->options['default_table_type''BDB';
  381.             case 'BDB':
  382.             case 'INNODB':
  383.             case 'GEMINI':
  384.                 $this->supported['transactions'= true;
  385.                 break;
  386.             case 'HEAP':
  387.             case 'ISAM':
  388.             case 'MERGE':
  389.             case 'MRG_MYISAM':
  390.             case 'MYISAM':
  391.                 break;
  392.             default:
  393.                 $this->warnings[$default_table_type.
  394.                     ' is not a supported default table type';
  395.             }
  396.         }
  397.  
  398.         if ($this->options['use_transactions'&& !$this->supports('transactions')) {
  399.             $this->warnings[$this->options['default_table_type'].
  400.                 ' is not a transaction-safe default table type; switched to INNODB';
  401.             $this->options['default_table_type''INNODB';
  402.             $this->supported['transactions'= true;
  403.         }
  404.  
  405.         $this->supported['sub_selects''emulated';
  406.         $server_info $this->getServerVersion();
  407.         if (is_array($server_info)
  408.             && ($server_info['major'> 4
  409.                 || ($server_info['major'== 4 && $server_info['minor'>= 1)
  410.             )
  411.         {
  412.             $this->supported['sub_selects'= true;
  413.         }
  414.         return MDB2_OK;
  415.     }
  416.  
  417.     // }}}
  418.     // {{{ disconnect()
  419.  
  420.     /**
  421.      * Log out and disconnect from the database.
  422.      *
  423.      * @param  boolean $force if the disconnect should be forced even if the
  424.      *                         connection is opened persistently
  425.      * @return mixed true on success, false if not connected and error
  426.      *                 object on error
  427.      * @access public
  428.      */
  429.     function disconnect($force = true)
  430.     {
  431.         if (is_object($this->connection)) {
  432.             if ($this->in_transaction{
  433.                 $this->rollback();
  434.             }
  435.             if ($force{
  436.                 @mysqli_close($this->connection);
  437.             }
  438.         }
  439.         return parent::disconnect($force);
  440.     }
  441.  
  442.     // }}}
  443.     // {{{ _doQuery()
  444.  
  445.     /**
  446.      * Execute a query
  447.      * @param string $query  query
  448.      * @param boolean $is_manip  if the query is a manipulation query
  449.      * @param resource $connection 
  450.      * @param string $database_name 
  451.      * @return result or error object
  452.      * @access protected
  453.      */
  454.     function _doQuery($query$is_manip = false$connection = null$database_name = null)
  455.     {
  456.         $this->last_query $query;
  457.         $this->debug($query'query'$is_manip);
  458.         if ($this->options['disable_query']{
  459.             if ($is_manip{
  460.                 return 0;
  461.             }
  462.             return null;
  463.         }
  464.  
  465.         if (is_null($connection)) {
  466.             $connection $this->getConnection();
  467.             if (PEAR::isError($connection)) {
  468.                 return $connection;
  469.             }
  470.         }
  471.         if (is_null($database_name)) {
  472.             $database_name $this->database_name;
  473.         }
  474.  
  475.         if ($database_name{
  476.             if ($database_name != $this->connected_database_name{
  477.                 if (!@mysqli_select_db($connection$database_name)) {
  478.                     return $this->raiseError();
  479.                 }
  480.                 $this->connected_database_name $database_name;
  481.             }
  482.         }
  483.  
  484.         $function $this->options['multi_query''mysqli_multi_query' :
  485.             ($this->options['result_buffering''mysqli_query' 'mysqli_unbuffered_query');
  486.         $result @$function($connection$query);
  487.         if (!$result{
  488.             return $this->raiseError();
  489.         }
  490.  
  491.         if ($this->options['multi_query']{
  492.             if ($this->options['result_buffering']{
  493.                 if (!($result @mysqli_store_result($connection))) {
  494.                     $this->raiseError();
  495.                 }
  496.             elseif (!($result @mysqli_use_result($connection))) {
  497.                 $this->raiseError();
  498.             }
  499.         }
  500.  
  501.         return $result;
  502.     }
  503.  
  504.     // }}}
  505.     // {{{ _affectedRows()
  506.  
  507.     /**
  508.      * returns the number of rows affected
  509.      *
  510.      * @param resource $result 
  511.      * @param resource $connection 
  512.      * @return mixed MDB2 Error Object or the number of rows affected
  513.      * @access private
  514.      */
  515.     function _affectedRows($connection$result = null)
  516.     {
  517.         if (is_null($connection)) {
  518.             $connection $this->getConnection();
  519.             if (PEAR::isError($connection)) {
  520.                 return $connection;
  521.             }
  522.         }
  523.         return @mysqli_affected_rows($connection);
  524.     }
  525.  
  526.     // }}}
  527.     // {{{ _modifyQuery()
  528.  
  529.     /**
  530.      * Changes a query string for various DBMS specific reasons
  531.      *
  532.      * @param string $query  query to modify
  533.      * @param boolean $is_manip  if it is a DML query
  534.      * @param integer $limit  limit the number of rows
  535.      * @param integer $offset  start reading from given offset
  536.      * @return string modified query
  537.      * @access protected
  538.      */
  539.     function _modifyQuery($query$is_manip$limit$offset)
  540.     {
  541.         if ($limit > 0
  542.             && !preg_match('/LIMIT\s*\d(\s*(,|OFFSET)\s*\d+)?/i'$query)
  543.         {
  544.             $query rtrim($query);
  545.             if (substr($query-1== ';'{
  546.                 $query substr($query0-1);
  547.             }
  548.             if ($is_manip{
  549.                 return $query . " LIMIT $limit";
  550.             else {
  551.                 return $query . " LIMIT $offset$limit";
  552.             }
  553.         }
  554.         return $query;
  555.     }
  556.  
  557.     // }}}
  558.     // {{{ getServerVersion()
  559.  
  560.     /**
  561.      * return version information about the server
  562.      *
  563.      * @param string     $native  determines if the raw version string should be returned
  564.      * @return mixed array/string with version information or MDB2 error object
  565.      * @access public
  566.      */
  567.     function getServerVersion($native = false)
  568.     {
  569.         $connection $this->getConnection();
  570.         if (PEAR::isError($connection)) {
  571.             return $connection;
  572.         }
  573.         if ($this->connected_server_info{
  574.             $server_info $this->connected_server_info;
  575.         else {
  576.             $server_info @mysqli_get_server_info($connection);
  577.         }
  578.         if (!$server_info{
  579.             return $this->raiseError();
  580.         }
  581.         // cache server_info
  582.         $this->connected_server_info $server_info;
  583.         if (!$native{
  584.             $tmp explode('.'$server_info3);
  585.             if (isset($tmp[2]&& strpos($tmp[2]'-')) {
  586.                 $tmp2 explode('-'@$tmp[2]2);
  587.             else {
  588.                 $tmp2[0= isset($tmp[2]$tmp[2: null;
  589.                 $tmp2[1= null;
  590.             }
  591.             $server_info = array(
  592.                 'major' => isset($tmp[0]$tmp[0: null,
  593.                 'minor' => isset($tmp[1]$tmp[1: null,
  594.                 'patch' => $tmp2[0],
  595.                 'extra' => $tmp2[1],
  596.                 'native' => $server_info,
  597.             );
  598.         }
  599.         return $server_info;
  600.     }
  601.  
  602.     // }}}
  603.     // {{{ prepare()
  604.  
  605.     /**
  606.      * Prepares a query for multiple execution with execute().
  607.      * With some database backends, this is emulated.
  608.      * prepare() requires a generic query as string like
  609.      * 'INSERT INTO numbers VALUES(?,?)' or
  610.      * 'INSERT INTO numbers VALUES(:foo,:bar)'.
  611.      * The ? and :[a-zA-Z] and  are placeholders which can be set using
  612.      * bindParam() and the query can be send off using the execute() method.
  613.      *
  614.      * @param string $query the query to prepare
  615.      * @param mixed   $types  array that contains the types of the placeholders
  616.      * @param mixed   $result_types  array that contains the types of the columns in
  617.      *                         the result set or MDB2_PREPARE_RESULT, if set to
  618.      *                         MDB2_PREPARE_MANIP the query is handled as a manipulation query
  619.      * @param mixed   $lobs   key (field) value (parameter) pair for all lob placeholders
  620.      * @return mixed resource handle for the prepared query on success, a MDB2
  621.      *         error on failure
  622.      * @access public
  623.      * @see bindParam, execute
  624.      */
  625.     function &prepare($query$types = null$result_types = null)
  626.     {
  627.         if ($result_types !== MDB2_PREPARE_MANIP{
  628.             $obj =parent::prepare($query$types$result_types);
  629.             return $obj;
  630.         }
  631.         $is_manip = true;
  632.         $offset $this->offset;
  633.         $limit $this->limit;
  634.         $this->offset $this->limit = 0;
  635.         $query $this->_modifyQuery($query$is_manip$limit$offset);
  636.         $this->debug($query'prepare'$is_manip);
  637.         $placeholder_type_guess $placeholder_type = null;
  638.         $question '?';
  639.         $colon ':';
  640.         $positions = array();
  641.         $position = 0;
  642.         while ($position strlen($query)) {
  643.             $q_position strpos($query$question$position);
  644.             $c_position strpos($query$colon$position);
  645.             if ($q_position && $c_position{
  646.                 $p_position min($q_position$c_position);
  647.             elseif ($q_position{
  648.                 $p_position $q_position;
  649.             elseif ($c_position{
  650.                 $p_position $c_position;
  651.             else {
  652.                 break;
  653.             }
  654.             if (is_null($placeholder_type)) {
  655.                 $placeholder_type_guess $query[$p_position];
  656.             }
  657.             if (is_int($quote strpos($query"'"$position)) && $quote $p_position{
  658.                 if (!is_int($end_quote strpos($query"'"$quote + 1))) {
  659.                     $err =$this->raiseError(MDB2_ERROR_SYNTAXnullnull,
  660.                         'prepare: query with an unterminated text string specified');
  661.                     return $err;
  662.                 }
  663.                 switch ($this->escape_quotes{
  664.                 case '':
  665.                 case "'":
  666.                     $position $end_quote + 1;
  667.                     break;
  668.                 default:
  669.                     if ($end_quote == $quote + 1{
  670.                         $position $end_quote + 1;
  671.                     else {
  672.                         if ($query[$end_quote-1== $this->escape_quotes{
  673.                             $position $end_quote;
  674.                         else {
  675.                             $position $end_quote + 1;
  676.                         }
  677.                     }
  678.                     break;
  679.                 }
  680.             elseif ($query[$position== $placeholder_type_guess{
  681.                 if (is_null($placeholder_type)) {
  682.                     $placeholder_type $query[$p_position];
  683.                     $question $colon $placeholder_type;
  684.                 }
  685.                 if ($placeholder_type == ':'{
  686.                     $parameter preg_replace('/^.{'.($position+1).'}([a-z0-9_]+).*$/si''\\1'$query);
  687.                     if ($parameter === ''{
  688.                         $err =$this->raiseError(MDB2_ERROR_SYNTAXnullnull,
  689.                             'prepare: named parameter with an empty name');
  690.                         return $err;
  691.                     }
  692.                     $positions[$parameter$p_position;
  693.                     $query substr_replace($query'?'$positionstrlen($parameter)+1);
  694.                 else {
  695.                     $positions[$p_position;
  696.                 }
  697.                 $position $p_position + 1;
  698.             else {
  699.                 $position $p_position;
  700.             }
  701.         }
  702.         $connection $this->getConnection();
  703.         if (PEAR::isError($connection)) {
  704.             return $connection;
  705.         }
  706.         $statement @mysqli_prepare($connection$query);
  707.         if (!$statement{
  708.             $err =$this->raiseError();
  709.             return $err;
  710.         }
  711.         $class_name 'MDB2_Statement_'.$this->phptype;
  712.         $obj =new $class_name($this$statement$positions$query$types$result_types$is_manip$limit$offset);
  713.         return $obj;
  714.     }
  715.  
  716.     // }}}
  717.     // {{{ replace()
  718.  
  719.     /**
  720.      * Execute a SQL REPLACE query. A REPLACE query is identical to a INSERT
  721.      * query, except that if there is already a row in the table with the same
  722.      * key field values, the REPLACE query just updates its values instead of
  723.      * inserting a new row.
  724.      *
  725.      * The REPLACE type of query does not make part of the SQL standards. Since
  726.      * practically only MySQL implements it natively, this type of query is
  727.      * emulated through this method for other DBMS using standard types of
  728.      * queries inside a transaction to assure the atomicity of the operation.
  729.      *
  730.      * @access public
  731.      *
  732.      * @param string $table name of the table on which the REPLACE query will
  733.      *   be executed.
  734.      * @param array $fields associative array that describes the fields and the
  735.      *   values that will be inserted or updated in the specified table. The
  736.      *   indexes of the array are the names of all the fields of the table. The
  737.      *   values of the array are also associative arrays that describe the
  738.      *   values and other properties of the table fields.
  739.      *
  740.      *   Here follows a list of field properties that need to be specified:
  741.      *
  742.      *     value:
  743.      *           Value to be assigned to the specified field. This value may be
  744.      *           of specified in database independent type format as this
  745.      *           function can perform the necessary datatype conversions.
  746.      *
  747.      *     Default:
  748.      *           this property is required unless the Null property
  749.      *           is set to 1.
  750.      *
  751.      *     type
  752.      *           Name of the type of the field. Currently, all types Metabase
  753.      *           are supported except for clob and blob.
  754.      *
  755.      *     Default: no type conversion
  756.      *
  757.      *     null
  758.      *           Boolean property that indicates that the value for this field
  759.      *           should be set to null.
  760.      *
  761.      *           The default value for fields missing in INSERT queries may be
  762.      *           specified the definition of a table. Often, the default value
  763.      *           is already null, but since the REPLACE may be emulated using
  764.      *           an UPDATE query, make sure that all fields of the table are
  765.      *           listed in this function argument array.
  766.      *
  767.      *     Default: 0
  768.      *
  769.      *     key
  770.      *           Boolean property that indicates that this field should be
  771.      *           handled as a primary key or at least as part of the compound
  772.      *           unique index of the table that will determine the row that will
  773.      *           updated if it exists or inserted a new row otherwise.
  774.      *
  775.      *           This function will fail if no key field is specified or if the
  776.      *           value of a key field is set to null because fields that are
  777.      *           part of unique index they may not be null.
  778.      *
  779.      *     Default: 0
  780.      *
  781.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  782.      */
  783.     function replace($table$fields)
  784.     {
  785.         $count count($fields);
  786.         $query $values '';
  787.         $keys $colnum = 0;
  788.         for (reset($fields)$colnum $countnext($fields)$colnum++{
  789.             $name key($fields);
  790.             if ($colnum > 0{
  791.                 $query .= ',';
  792.                 $values.= ',';
  793.             }
  794.             $query.= $name;
  795.             if (isset($fields[$name]['null']&& $fields[$name]['null']{
  796.                 $value 'NULL';
  797.             else {
  798.                 $value $this->quote($fields[$name]['value']$fields[$name]['type']);
  799.             }
  800.             $values.= $value;
  801.             if (isset($fields[$name]['key']&& $fields[$name]['key']{
  802.                 if ($value === 'NULL'{
  803.                     return $this->raiseError(MDB2_ERROR_CANNOT_REPLACEnullnull,
  804.                         'replace: key value '.$name.' may not be NULL');
  805.                 }
  806.                 $keys++;
  807.             }
  808.         }
  809.         if ($keys == 0{
  810.             return $this->raiseError(MDB2_ERROR_CANNOT_REPLACEnullnull,
  811.                 'replace: not specified which fields are keys');
  812.         }
  813.  
  814.         $connection $this->getConnection();
  815.         if (PEAR::isError($connection)) {
  816.             return $connection;
  817.         }
  818.  
  819.         $query = "REPLACE INTO $table ($query) VALUES ($values)";
  820.         $this->last_query $query;
  821.         $this->debug($query'query'true);
  822.         $result $this->_doQuery($querytrue$connection);
  823.         if (PEAR::isError($result)) {
  824.             return $result;
  825.         }
  826.         return $this->_affectedRows($connection$result);
  827.     }
  828.  
  829.     // }}}
  830.     // {{{ nextID()
  831.  
  832.     /**
  833.      * returns the next free id of a sequence
  834.      *
  835.      * @param string $seq_name name of the sequence
  836.      * @param boolean $ondemand when true the seqence is
  837.      *                           automatic created, if it
  838.      *                           not exists
  839.      *
  840.      * @return mixed MDB2 Error Object or id
  841.      * @access public
  842.      */
  843.     function nextID($seq_name$ondemand = true)
  844.     {
  845.         $sequence_name $this->quoteIdentifier($this->getSequenceName($seq_name)true);
  846.         $seqcol_name $this->quoteIdentifier($this->options['seqcol_name']true);
  847.         $query = "INSERT INTO $sequence_name ($seqcol_name) VALUES (NULL)";
  848.         $this->expectError(MDB2_ERROR_NOSUCHTABLE);
  849.         $result $this->_doQuery($querytrue);
  850.         $this->popExpect();
  851.         if (PEAR::isError($result)) {
  852.             if ($ondemand && $result->getCode(== MDB2_ERROR_NOSUCHTABLE{
  853.                 $this->loadModule('Manager'nulltrue);
  854.                 // Since we are creating the sequence on demand
  855.                 // we know the first id = 1 so initialize the
  856.                 // sequence at 2
  857.                 $result $this->manager->createSequence($seq_name2);
  858.                 if (PEAR::isError($result)) {
  859.                     return $this->raiseError(MDB2_ERRORnullnull,
  860.                         'nextID: on demand sequence '.$seq_name.' could not be created');
  861.                 else {
  862.                     // First ID of a newly created sequence is 1
  863.                     return 1;
  864.                 }
  865.             }
  866.             return $result;
  867.         }
  868.         $value $this->lastInsertID();
  869.         if (is_numeric($value)) {
  870.             $query = "DELETE FROM $sequence_name WHERE $seqcol_name < $value";
  871.             $result $this->_doQuery($querytrue);
  872.             if (PEAR::isError($result)) {
  873.                 $this->warnings['nextID: could not delete previous sequence table values from '.$seq_name;
  874.             }
  875.         }
  876.         return $value;
  877.     }
  878.  
  879.     // }}}
  880.     // {{{ lastInsertID()
  881.  
  882.     /**
  883.      * returns the autoincrement ID if supported or $id
  884.      *
  885.      * @param mixed $id value as returned by getBeforeId()
  886.      * @param string $table name of the table into which a new row was inserted
  887.      * @return mixed MDB2 Error Object or id
  888.      * @access public
  889.      */
  890.     function lastInsertID($table = null$field = null)
  891.     {
  892.         $connection $this->getConnection();
  893.         if (PEAR::isError($connection)) {
  894.             return $connection;
  895.         }
  896.         $value @mysqli_insert_id($connection);
  897.         if (!$value{
  898.             return $this->raiseError();
  899.         }
  900.         return $value;
  901.     }
  902.  
  903.     // }}}
  904.     // {{{ currID()
  905.  
  906.     /**
  907.      * returns the current id of a sequence
  908.      *
  909.      * @param string $seq_name name of the sequence
  910.      * @return mixed MDB2 Error Object or id
  911.      * @access public
  912.      */
  913.     function currID($seq_name)
  914.     {
  915.         $sequence_name $this->quoteIdentifier($this->getSequenceName($seq_name)true);
  916.         $seqcol_name $this->quoteIdentifier($this->options['seqcol_name']true);
  917.         $query = "SELECT MAX($seqcol_name) FROM $sequence_name";
  918.         return $this->queryOne($query'integer');
  919.     }
  920. }
  921.  
  922. class MDB2_Result_mysqli extends MDB2_Result_Common
  923. {
  924.     // }}}
  925.     // {{{ fetchRow()
  926.  
  927.     /**
  928.      * Fetch a row and insert the data into an existing array.
  929.      *
  930.      * @param int       $fetchmode  how the array data should be indexed
  931.      * @param int    $rownum    number of the row where the data can be found
  932.      * @return int data array on success, a MDB2 error on failure
  933.      * @access public
  934.      */
  935.     function &fetchRow($fetchmode = MDB2_FETCHMODE_DEFAULT$rownum = null)
  936.     {
  937.         if (!is_null($rownum)) {
  938.             $seek $this->seek($rownum);
  939.             if (PEAR::isError($seek)) {
  940.                 return $seek;
  941.             }
  942.         }
  943.         if ($fetchmode == MDB2_FETCHMODE_DEFAULT{
  944.             $fetchmode $this->db->fetchmode;
  945.         }
  946.         if ($fetchmode MDB2_FETCHMODE_ASSOC{
  947.             $row @mysqli_fetch_assoc($this->result);
  948.             if (is_array($row)
  949.                 && $this->db->options['portability'MDB2_PORTABILITY_FIX_CASE
  950.             {
  951.                 $row array_change_key_case($row$this->db->options['field_case']);
  952.             }
  953.         else {
  954.            $row @mysqli_fetch_row($this->result);
  955.         }
  956.  
  957.         if (!$row{
  958.             if ($this->result === false{
  959.                 $err =$this->db->raiseError(MDB2_ERROR_NEED_MORE_DATAnullnull,
  960.                     'fetchRow: resultset has already been freed');
  961.                 return $err;
  962.             }
  963.             $null = null;
  964.             return $null;
  965.         }
  966.         if ($this->db->options['portability'MDB2_PORTABILITY_EMPTY_TO_NULL{
  967.             $this->db->_fixResultArrayValues($rowMDB2_PORTABILITY_EMPTY_TO_NULL);
  968.         }
  969.         if (!empty($this->values)) {
  970.             $this->_assignBindColumns($row);
  971.         }
  972.         if (!empty($this->types)) {
  973.             $row $this->db->datatype->convertResultRow($this->types$row);
  974.         }
  975.         if ($fetchmode === MDB2_FETCHMODE_OBJECT{
  976.             $object_class $this->db->options['fetch_class'];
  977.             if ($object_class == 'stdClass'{
  978.                 $row = (object) $row;
  979.             else {
  980.                 $row &new $object_class($row);
  981.             }
  982.         }
  983.         ++$this->rownum;
  984.         return $row;
  985.     }
  986.  
  987.     // }}}
  988.     // {{{ _getColumnNames()
  989.  
  990.     /**
  991.      * Retrieve the names of columns returned by the DBMS in a query result.
  992.      *
  993.      * @return mixed                an associative array variable
  994.      *                               that will hold the names of columns. The
  995.      *                               indexes of the array are the column names
  996.      *                               mapped to lower case and the values are the
  997.      *                               respective numbers of the columns starting
  998.      *                               from 0. Some DBMS may not return any
  999.      *                               columns when the result set does not
  1000.      *                               contain any rows.
  1001.      *
  1002.      *                               a MDB2 error on failure
  1003.      * @access private
  1004.      */
  1005.     function _getColumnNames()
  1006.     {
  1007.         $columns = array();
  1008.         $numcols $this->numCols();
  1009.         if (PEAR::isError($numcols)) {
  1010.             return $numcols;
  1011.         }
  1012.         for ($column = 0; $column $numcols$column++{
  1013.             $column_info @mysqli_fetch_field_direct($this->result$column);
  1014.             $columns[$column_info->name$column;
  1015.         }
  1016.         if ($this->db->options['portability'MDB2_PORTABILITY_FIX_CASE{
  1017.             $columns array_change_key_case($columns$this->db->options['field_case']);
  1018.         }
  1019.         return $columns;
  1020.     }
  1021.  
  1022.     // }}}
  1023.     // {{{ numCols()
  1024.  
  1025.     /**
  1026.      * Count the number of columns returned by the DBMS in a query result.
  1027.      *
  1028.      * @return mixed integer value with the number of columns, a MDB2 error
  1029.      *                        on failure
  1030.      * @access public
  1031.      */
  1032.     function numCols()
  1033.     {
  1034.         $cols @mysqli_num_fields($this->result);
  1035.         if (is_null($cols)) {
  1036.             if ($this->result === false{
  1037.                 return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATAnullnull,
  1038.                     'numCols: resultset has already been freed');
  1039.             elseif (is_null($this->result)) {
  1040.                 return count($this->types);
  1041.             }
  1042.             return $this->db->raiseError();
  1043.         }
  1044.         return $cols;
  1045.     }
  1046.  
  1047.     // }}}
  1048.     // {{{ nextResult()
  1049.  
  1050.     /**
  1051.      * Move the internal result pointer to the next available result
  1052.      *
  1053.      * @param valid result resource
  1054.      * @return true on success, false if there is no more result set or an error object on failure
  1055.      * @access public
  1056.      */
  1057.     function nextResult()
  1058.     {
  1059.         $connection $this->db->getConnection();
  1060.         if (PEAR::isError($connection)) {
  1061.             return $connection;
  1062.         }
  1063.  
  1064.         if (!@mysqli_more_results($connection)) {
  1065.             return false;
  1066.         }
  1067.         if (!@mysqli_next_result($connection)) {
  1068.             return false;
  1069.         }
  1070.         if (!($this->result @mysqli_use_result($connection))) {
  1071.             return false;
  1072.         }
  1073.         return MDB2_OK;
  1074.     }
  1075.  
  1076.     // }}}
  1077.     // {{{ free()
  1078.  
  1079.     /**
  1080.      * Free the internal resources associated with result.
  1081.      *
  1082.      * @return boolean true on success, false if result is invalid
  1083.      * @access public
  1084.      */
  1085.     function free()
  1086.     {
  1087.         @mysqli_free_result($this->result);
  1088.         $this->result = false;
  1089.         return MDB2_OK;
  1090.     }
  1091. }
  1092.  
  1093. {
  1094.     // }}}
  1095.     // {{{ seek()
  1096.  
  1097.     /**
  1098.      * seek to a specific row in a result set
  1099.      *
  1100.      * @param int    $rownum    number of the row where the data can be found
  1101.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  1102.      * @access public
  1103.      */
  1104.     function seek($rownum = 0)
  1105.     {
  1106.         if ($this->rownum != ($rownum - 1&& !@mysqli_data_seek($this->result$rownum)) {
  1107.             if ($this->result === false{
  1108.                 return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATAnullnull,
  1109.                     'seek: resultset has already been freed');
  1110.             elseif (is_null($this->result)) {
  1111.                 return MDB2_OK;
  1112.             }
  1113.             return $this->db->raiseError(MDB2_ERROR_INVALIDnullnull,
  1114.                 'seek: tried to seek to an invalid row number ('.$rownum.')');
  1115.         }
  1116.         $this->rownum $rownum - 1;
  1117.         return MDB2_OK;
  1118.     }
  1119.  
  1120.     // }}}
  1121.     // {{{ valid()
  1122.  
  1123.     /**
  1124.      * check if the end of the result set has been reached
  1125.      *
  1126.      * @return mixed true or false on sucess, a MDB2 error on failure
  1127.      * @access public
  1128.      */
  1129.     function valid()
  1130.     {
  1131.         $numrows $this->numRows();
  1132.         if (PEAR::isError($numrows)) {
  1133.             return $numrows;
  1134.         }
  1135.         return $this->rownum ($numrows - 1);
  1136.     }
  1137.  
  1138.     // }}}
  1139.     // {{{ numRows()
  1140.  
  1141.     /**
  1142.      * returns the number of rows in a result object
  1143.      *
  1144.      * @return mixed MDB2 Error Object or the number of rows
  1145.      * @access public
  1146.      */
  1147.     function numRows()
  1148.     {
  1149.         $rows @mysqli_num_rows($this->result);
  1150.         if (is_null($rows)) {
  1151.             if ($this->result === false{
  1152.                 return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATAnullnull,
  1153.                     'numRows: resultset has already been freed');
  1154.             elseif (is_null($this->result)) {
  1155.                 return 0;
  1156.             }
  1157.             return $this->db->raiseError();
  1158.         }
  1159.         return $rows;
  1160.     }
  1161.  
  1162.     // }}}
  1163.     // {{{ nextResult()
  1164.  
  1165.     /**
  1166.      * Move the internal result pointer to the next available result
  1167.      *
  1168.      * @param valid result resource
  1169.      * @return true on success, false if there is no more result set or an error object on failure
  1170.      * @access public
  1171.      */
  1172.     function nextResult()
  1173.     {
  1174.         $connection $this->db->getConnection();
  1175.         if (PEAR::isError($connection)) {
  1176.             return $connection;
  1177.         }
  1178.  
  1179.         if (!@mysqli_more_results($connection)) {
  1180.             return false;
  1181.         }
  1182.         if (!@mysqli_next_result($connection)) {
  1183.             return false;
  1184.         }
  1185.         if (!($this->result @mysqli_store_result($connection))) {
  1186.             return false;
  1187.         }
  1188.         return MDB2_OK;
  1189.     }
  1190. }
  1191.  
  1192. class MDB2_Statement_mysqli extends MDB2_Statement_Common
  1193. {
  1194.     // {{{ _execute()
  1195.  
  1196.     /**
  1197.      * Execute a prepared query statement helper method.
  1198.      *
  1199.      * @param mixed $result_class string which specifies which result class to use
  1200.      * @param mixed $result_wrap_class string which specifies which class to wrap results in
  1201.      * @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure
  1202.      * @access private
  1203.      */
  1204.     function &_execute($result_class = true$result_wrap_class = false)
  1205.     {
  1206.         if (!$this->is_manip{
  1207.             $result =parent::_execute($result_class$result_wrap_class);
  1208.             return $result;
  1209.         }
  1210.         $this->db->last_query = $this->query;
  1211.         $this->db->debug($this->query'execute');
  1212.         if ($this->db->getOption('disable_query')) {
  1213.             if ($this->is_manip{
  1214.                 $return = 0;
  1215.                 return $return;
  1216.             }
  1217.             $null = null;
  1218.             return $null;
  1219.         }
  1220.  
  1221.         $connection $this->db->getConnection();
  1222.         if (PEAR::isError($connection)) {
  1223.             return $connection;
  1224.         }
  1225.  
  1226.         if (!empty($this->positions)) {
  1227.             $parameters = array(0 => $this->statement1 => '');
  1228.             $lobs = array();
  1229.             $i = 0;
  1230.             foreach ($this->positions as $parameter => $foo{
  1231.                 if (!array_key_exists($parameter$this->values)) {
  1232.                     return $this->db->raiseError();
  1233.                 }
  1234.                 $value $this->values[$parameter];
  1235.                 $type array_key_exists($parameter$this->types$this->types[$parameter: null;
  1236.                 if (is_resource($value|| $type == 'clob' || $type == 'blob'{
  1237.                     $parameters[= null;
  1238.                     $parameters[1].= 'b';
  1239.                     $lobs[$i$parameter;
  1240.                 else {
  1241.                     $parameters[$this->db->quote($value$typefalse);
  1242.                     $parameters[1].= $this->db->datatype->mapPrepareDatatype($type);
  1243.                 }
  1244.                 ++$i;
  1245.             }
  1246.  
  1247.             $result @call_user_func_array('mysqli_stmt_bind_param'$parameters);
  1248.             if ($result === false{
  1249.                 $err =$this->db->raiseError();
  1250.                 return $err;
  1251.             }
  1252.  
  1253.             foreach ($lobs as $i => $parameter{
  1254.                 $value $this->values[$parameter];
  1255.                 $close = false;
  1256.                 if (!is_resource($value)) {
  1257.                     $close = true;
  1258.                     if (preg_match('/^(\w+:\/\/)(.*)$/'$value$match)) {
  1259.                         if ($match[1== 'file://'{
  1260.                             $value $match[2];
  1261.                         }
  1262.                         $value @fopen($value'r');
  1263.                     else {
  1264.                         $fp @tmpfile();
  1265.                         @fwrite($fp$value);
  1266.                         @rewind($fp);
  1267.                         $value $fp;
  1268.                     }
  1269.                 }
  1270.                 while (!@feof($value)) {
  1271.                     $data @fread($value$this->db->options['lob_buffer_length']);
  1272.                     @mysqli_stmt_send_long_data($this->statement$i$data);
  1273.                 }
  1274.                 if ($close{
  1275.                     @fclose($value);
  1276.                 }
  1277.             }
  1278.         }
  1279.  
  1280.         if (!@mysqli_stmt_execute($this->statement)) {
  1281.             $err =$this->db->raiseError();
  1282.             return $err;
  1283.         }
  1284.  
  1285.         if ($this->is_manip{
  1286.             $affected_rows @mysqli_stmt_affected_rows($this->statement);
  1287.             return $affected_rows;
  1288.         }
  1289.  
  1290.         if ($this->db->options['result_buffering']{
  1291.             @mysqli_stmt_store_result($this->statement);
  1292.         }
  1293.  
  1294.         $result =$this->db->_wrapResult($this->statement$this->result_types,
  1295.             $result_class$result_wrap_class);
  1296.         return $result;
  1297.     }
  1298.  
  1299.     // }}}
  1300.  
  1301.     // }}}
  1302.  
  1303.     // }}}
  1304.     // {{{ free()
  1305.  
  1306.     /**
  1307.      * Release resources allocated for the specified prepared query.
  1308.      *
  1309.      * @return mixed MDB2_OK on success, a MDB2 error on failure
  1310.      * @access public
  1311.      */
  1312.     function free()
  1313.     {
  1314.         if (!$this->is_manip{
  1315.             return parent::free();
  1316.         }
  1317.         if (!@mysqli_stmt_close($this->statement)) {
  1318.             return $this->db->raiseError();
  1319.         }
  1320.         return MDB2_OK;
  1321.     }
  1322. }
  1323. ?>

Documentation generated on Mon, 11 Mar 2019 14:39:13 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.