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

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