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

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