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

Source for file mysql.php

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

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