Source for file mysqli.php

Documentation is available at mysqli.php

  1. <?php
  2. /**
  3.  * @package     Joomla.Platform
  4.  * @subpackage  Database
  5.  *
  6.  * @copyright   Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
  7.  * @license     GNU General Public License version 2 or later; see LICENSE
  8.  */
  9.  
  10. defined('JPATH_PLATFORM'or die;
  11.  
  12. /**
  13.  * MySQLi database driver
  14.  *
  15.  * @package     Joomla.Platform
  16.  * @subpackage  Database
  17.  * @see         http://php.net/manual/en/book.mysqli.php
  18.  * @since       12.1
  19.  */
  20. {
  21.     /**
  22.      * The name of the database driver.
  23.      *
  24.      * @var    string 
  25.      * @since  12.1
  26.      */
  27.     public $name = 'mysqli';
  28.  
  29.     /**
  30.      * The character(s) used to quote SQL statement names such as table names or field names,
  31.      * etc. The child classes should define this as necessary.  If a single character string the
  32.      * same character is used for both sides of the quoted name, else the first character will be
  33.      * used for the opening quote and the second for the closing quote.
  34.      *
  35.      * @var    string 
  36.      * @since  12.2
  37.      */
  38.     protected $nameQuote = '`';
  39.  
  40.     /**
  41.      * The null or zero representation of a timestamp for the database driver.  This should be
  42.      * defined in child classes to hold the appropriate value for the engine.
  43.      *
  44.      * @var    string 
  45.      * @since  12.2
  46.      */
  47.     protected $nullDate = '0000-00-00 00:00:00';
  48.  
  49.     /**
  50.      * @var    string  The minimum supported database version.
  51.      * @since  12.2
  52.      */
  53.     protected static $dbMinimum '5.0.4';
  54.  
  55.     /**
  56.      * Constructor.
  57.      *
  58.      * @param   array  $options  List of options used to configure the connection
  59.      *
  60.      * @since   12.1
  61.      */
  62.     public function __construct($options)
  63.     {
  64.         // Get some basic values from the options.
  65.         $options['host'(isset($options['host'])) $options['host''localhost';
  66.         $options['user'(isset($options['user'])) $options['user''root';
  67.         $options['password'(isset($options['password'])) $options['password''';
  68.         $options['database'(isset($options['database'])) $options['database''';
  69.         $options['select'(isset($options['select'])) ? (bool) $options['select'true;
  70.         $options['port'null;
  71.         $options['socket'null;
  72.  
  73.         // Finalize initialisation.
  74.         parent::__construct($options);
  75.     }
  76.  
  77.     /**
  78.      * Destructor.
  79.      *
  80.      * @since   12.1
  81.      */
  82.     public function __destruct()
  83.     {
  84.         $this->disconnect();
  85.     }
  86.  
  87.     /**
  88.      * Connects to the database if needed.
  89.      *
  90.      * @return  void  Returns void if the database connected successfully.
  91.      *
  92.      * @since   12.1
  93.      * @throws  RuntimeException
  94.      */
  95.     public function connect()
  96.     {
  97.         if ($this->connection)
  98.         {
  99.             return;
  100.         }
  101.  
  102.         /*
  103.          * Unlike mysql_connect(), mysqli_connect() takes the port and socket as separate arguments. Therefore, we
  104.          * have to extract them from the host string.
  105.          */
  106.         $port = isset($this->options['port']$this->options['port'3306;
  107.  
  108.         if (preg_match('/^(?P<host>((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))(:(?P<port>.+))?$/'$this->options['host']$matches))
  109.         {
  110.             // It's an IPv4 address with ot without port
  111.             $this->options['host'$matches['host'];
  112.  
  113.             if (!empty($matches['port']))
  114.             {
  115.                 $port $matches['port'];
  116.             }
  117.         }
  118.         elseif (preg_match('/^(?P<host>\[.*\])(:(?P<port>.+))?$/'$this->options['host']$matches))
  119.         {
  120.             // We assume square-bracketed IPv6 address with or without port, e.g. [fe80:102::2%eth1]:3306
  121.             $this->options['host'$matches['host'];
  122.  
  123.             if (!empty($matches['port']))
  124.             {
  125.                 $port $matches['port'];
  126.             }
  127.         }
  128.         elseif (preg_match('/^(?P<host>(\w+:\/{2,3})?[a-z0-9\.\-]+)(:(?P<port>[^:]+))?$/i'$this->options['host']$matches))
  129.         {
  130.             // Named host (e.g domain.com or localhost) with ot without port
  131.             $this->options['host'$matches['host'];
  132.  
  133.             if (!empty($matches['port']))
  134.             {
  135.                 $port $matches['port'];
  136.             }
  137.         }
  138.         elseif (preg_match('/^:(?P<port>[^:]+)$/'$this->options['host']$matches))
  139.         {
  140.             // Empty host, just port, e.g. ':3306'
  141.             $this->options['host''localhost';
  142.             $port $matches['port'];
  143.         }
  144.         // ... else we assume normal (naked) IPv6 address, so host and port stay as they are or default
  145.  
  146.         // Get the port number or socket name
  147.         if (is_numeric($port))
  148.         {
  149.             $this->options['port'= (int) $port;
  150.         }
  151.         else
  152.         {
  153.             $this->options['socket'$port;
  154.         }
  155.  
  156.         // Make sure the MySQLi extension for PHP is installed and enabled.
  157.         if (!function_exists('mysqli_connect'))
  158.         {
  159.             throw new RuntimeException('The MySQL adapter mysqli is not available');
  160.         }
  161.  
  162.         $this->connection = @mysqli_connect(
  163.             $this->options['host']$this->options['user']$this->options['password']null$this->options['port']$this->options['socket']
  164.         );
  165.  
  166.         // Attempt to connect to the server.
  167.         if (!$this->connection)
  168.         {
  169.             throw new RuntimeException('Could not connect to MySQL.');
  170.         }
  171.  
  172.         // Set sql_mode to non_strict mode
  173.         mysqli_query($this->connection"SET @@SESSION.sql_mode = '';");
  174.  
  175.         // If auto-select is enabled select the given database.
  176.         if ($this->options['select'&& !empty($this->options['database']))
  177.         {
  178.             $this->select($this->options['database']);
  179.         }
  180.  
  181.         // Set charactersets (needed for MySQL 4.1.2+).
  182.         $this->setUTF();
  183.  
  184.         // Turn MySQL profiling ON in debug mode:
  185.         if ($this->debug && $this->hasProfiling())
  186.         {
  187.             mysqli_query($this->connection"SET profiling_history_size = 100;");
  188.             mysqli_query($this->connection"SET profiling = 1;");
  189.         }
  190.     }
  191.  
  192.     /**
  193.      * Disconnects the database.
  194.      *
  195.      * @return  void 
  196.      *
  197.      * @since   12.1
  198.      */
  199.     public function disconnect()
  200.     {
  201.         // Close the connection.
  202.         if ($this->connection)
  203.         {
  204.             foreach ($this->disconnectHandlers as $h)
  205.             {
  206.                 call_user_func_array($harray&$this));
  207.             }
  208.  
  209.             mysqli_close($this->connection);
  210.         }
  211.  
  212.         $this->connection = null;
  213.     }
  214.  
  215.     /**
  216.      * Method to escape a string for usage in an SQL statement.
  217.      *
  218.      * @param   string   $text   The string to be escaped.
  219.      * @param   boolean  $extra  Optional parameter to provide extra escaping.
  220.      *
  221.      * @return  string  The escaped string.
  222.      *
  223.      * @since   12.1
  224.      */
  225.     public function escape($text$extra false)
  226.     {
  227.         $this->connect();
  228.  
  229.         $result mysqli_real_escape_string($this->getConnection()$text);
  230.  
  231.         if ($extra)
  232.         {
  233.             $result addcslashes($result'%_');
  234.         }
  235.  
  236.         return $result;
  237.     }
  238.  
  239.     /**
  240.      * Test to see if the MySQL connector is available.
  241.      *
  242.      * @return  boolean  True on success, false otherwise.
  243.      *
  244.      * @since   12.1
  245.      */
  246.     public static function isSupported()
  247.     {
  248.         return (function_exists('mysqli_connect'));
  249.     }
  250.  
  251.     /**
  252.      * Determines if the connection to the server is active.
  253.      *
  254.      * @return  boolean  True if connected to the database engine.
  255.      *
  256.      * @since   12.1
  257.      */
  258.     public function connected()
  259.     {
  260.         if (is_object($this->connection))
  261.         {
  262.             return mysqli_ping($this->connection);
  263.         }
  264.  
  265.         return false;
  266.     }
  267.  
  268.     /**
  269.      * Drops a table from the database.
  270.      *
  271.      * @param   string   $tableName  The name of the database table to drop.
  272.      * @param   boolean  $ifExists   Optionally specify that the table must exist before it is dropped.
  273.      *
  274.      * @return  JDatabaseDriverMysqli  Returns this object to support chaining.
  275.      *
  276.      * @since   12.2
  277.      * @throws  RuntimeException
  278.      */
  279.     public function dropTable($tableName$ifExists true)
  280.     {
  281.         $this->connect();
  282.  
  283.         $query $this->getQuery(true);
  284.  
  285.         $this->setQuery('DROP TABLE ' ($ifExists 'IF EXISTS ' ''$query->quoteName($tableName));
  286.  
  287.         $this->execute();
  288.  
  289.         return $this;
  290.     }
  291.  
  292.     /**
  293.      * Get the number of affected rows for the previous executed SQL statement.
  294.      *
  295.      * @return  integer  The number of affected rows.
  296.      *
  297.      * @since   12.1
  298.      */
  299.     public function getAffectedRows()
  300.     {
  301.         $this->connect();
  302.  
  303.         return mysqli_affected_rows($this->connection);
  304.     }
  305.  
  306.     /**
  307.      * Method to get the database collation in use by sampling a text field of a table in the database.
  308.      *
  309.      * @return  mixed  The collation in use by the database (string) or boolean false if not supported.
  310.      *
  311.      * @since   12.2
  312.      * @throws  RuntimeException
  313.      */
  314.     public function getCollation()
  315.     {
  316.         $this->connect();
  317.  
  318.         $tables $this->getTableList();
  319.  
  320.         $this->setQuery('SHOW FULL COLUMNS FROM ' $tables[0]);
  321.         $array $this->loadAssocList();
  322.  
  323.         foreach ($array as $field)
  324.         {
  325.             if (!is_null($field['Collation']))
  326.             {
  327.                 return $field['Collation'];
  328.             }
  329.         }
  330.  
  331.         return null;
  332.     }
  333.  
  334.     /**
  335.      * Get the number of returned rows for the previous executed SQL statement.
  336.      *
  337.      * @param   resource  $cursor  An optional database cursor resource to extract the row count from.
  338.      *
  339.      * @return  integer   The number of returned rows.
  340.      *
  341.      * @since   12.1
  342.      */
  343.     public function getNumRows($cursor null)
  344.     {
  345.         return mysqli_num_rows($cursor $cursor $this->cursor);
  346.     }
  347.  
  348.     /**
  349.      * Shows the table CREATE statement that creates the given tables.
  350.      *
  351.      * @param   mixed  $tables  A table name or a list of table names.
  352.      *
  353.      * @return  array  A list of the create SQL for the tables.
  354.      *
  355.      * @since   12.1
  356.      * @throws  RuntimeException
  357.      */
  358.     public function getTableCreate($tables)
  359.     {
  360.         $this->connect();
  361.  
  362.         $result array();
  363.  
  364.         // Sanitize input to an array and iterate over the list.
  365.         settype($tables'array');
  366.         foreach ($tables as $table)
  367.         {
  368.             // Set the query to get the table CREATE statement.
  369.             $this->setQuery('SHOW CREATE table ' $this->quoteName($this->escape($table)));
  370.             $row $this->loadRow();
  371.  
  372.             // Populate the result array based on the create statements.
  373.             $result[$table$row[1];
  374.         }
  375.  
  376.         return $result;
  377.     }
  378.  
  379.     /**
  380.      * Retrieves field information about a given table.
  381.      *
  382.      * @param   string   $table     The name of the database table.
  383.      * @param   boolean  $typeOnly  True to only return field types.
  384.      *
  385.      * @return  array  An array of fields for the database table.
  386.      *
  387.      * @since   12.2
  388.      * @throws  RuntimeException
  389.      */
  390.     public function getTableColumns($table$typeOnly true)
  391.     {
  392.         $this->connect();
  393.  
  394.         $result array();
  395.  
  396.         // Set the query to get the table fields statement.
  397.         $this->setQuery('SHOW FULL COLUMNS FROM ' $this->quoteName($this->escape($table)));
  398.         $fields $this->loadObjectList();
  399.  
  400.         // If we only want the type as the value add just that to the list.
  401.         if ($typeOnly)
  402.         {
  403.             foreach ($fields as $field)
  404.             {
  405.                 $result[$field->Fieldpreg_replace("/[(0-9)]/"''$field->Type);
  406.             }
  407.         }
  408.         // If we want the whole field data object add that to the list.
  409.         else
  410.         {
  411.             foreach ($fields as $field)
  412.             {
  413.                 $result[$field->Field$field;
  414.             }
  415.         }
  416.  
  417.         return $result;
  418.     }
  419.  
  420.     /**
  421.      * Get the details list of keys for a table.
  422.      *
  423.      * @param   string  $table  The name of the table.
  424.      *
  425.      * @return  array  An array of the column specification for the table.
  426.      *
  427.      * @since   12.2
  428.      * @throws  RuntimeException
  429.      */
  430.     public function getTableKeys($table)
  431.     {
  432.         $this->connect();
  433.  
  434.         // Get the details columns information.
  435.         $this->setQuery('SHOW KEYS FROM ' $this->quoteName($table));
  436.         $keys $this->loadObjectList();
  437.  
  438.         return $keys;
  439.     }
  440.  
  441.     /**
  442.      * Method to get an array of all tables in the database.
  443.      *
  444.      * @return  array  An array of all the tables in the database.
  445.      *
  446.      * @since   12.2
  447.      * @throws  RuntimeException
  448.      */
  449.     public function getTableList()
  450.     {
  451.         $this->connect();
  452.  
  453.         // Set the query to get the tables statement.
  454.         $this->setQuery('SHOW TABLES');
  455.         $tables $this->loadColumn();
  456.  
  457.         return $tables;
  458.     }
  459.  
  460.     /**
  461.      * Get the version of the database connector.
  462.      *
  463.      * @return  string  The database connector version.
  464.      *
  465.      * @since   12.1
  466.      */
  467.     public function getVersion()
  468.     {
  469.         $this->connect();
  470.  
  471.         return mysqli_get_server_info($this->connection);
  472.     }
  473.  
  474.     /**
  475.      * Method to get the auto-incremented value from the last INSERT statement.
  476.      *
  477.      * @return  mixed  The value of the auto-increment field from the last inserted row.
  478.      *                  If the value is greater than maximal int value, it will return a string.
  479.      *
  480.      * @since   12.1
  481.      */
  482.     public function insertid()
  483.     {
  484.         $this->connect();
  485.  
  486.         return mysqli_insert_id($this->connection);
  487.     }
  488.  
  489.     /**
  490.      * Locks a table in the database.
  491.      *
  492.      * @param   string  $table  The name of the table to unlock.
  493.      *
  494.      * @return  JDatabaseDriverMysqli  Returns this object to support chaining.
  495.      *
  496.      * @since   12.2
  497.      * @throws  RuntimeException
  498.      */
  499.     public function lockTable($table)
  500.     {
  501.         $this->setQuery('LOCK TABLES ' $this->quoteName($table' WRITE')->execute();
  502.  
  503.         return $this;
  504.     }
  505.  
  506.     /**
  507.      * Execute the SQL statement.
  508.      *
  509.      * @return  mixed  A database cursor resource on success, boolean false on failure.
  510.      *
  511.      * @since   12.1
  512.      * @throws  RuntimeException
  513.      */
  514.     public function execute()
  515.     {
  516.         $this->connect();
  517.  
  518.         if (!is_object($this->connection))
  519.         {
  520.             JLog::add(JText::sprintf('JLIB_DATABASE_QUERY_FAILED'$this->errorNum$this->errorMsg)JLog::ERROR'database');
  521.             throw new RuntimeException($this->errorMsg$this->errorNum);
  522.         }
  523.  
  524.         // Take a local copy so that we don't modify the original query and cause issues later
  525.         $query $this->replacePrefix((string) $this->sql);
  526.  
  527.         if (!($this->sql instanceof JDatabaseQuery&& ($this->limit > || $this->offset > 0))
  528.         {
  529.             $query .= ' LIMIT ' $this->offset . ', ' $this->limit;
  530.         }
  531.  
  532.         // Increment the query counter.
  533.         $this->count++;
  534.  
  535.         // Reset the error values.
  536.         $this->errorNum = 0;
  537.         $this->errorMsg = '';
  538.         $memoryBefore null;
  539.  
  540.         // If debugging is enabled then let's log the query.
  541.         if ($this->debug)
  542.         {
  543.             // Add the query to the object queue.
  544.             $this->log[$query;
  545.  
  546.             JLog::add($queryJLog::DEBUG'databasequery');
  547.  
  548.             $this->timings[microtime(true);
  549.  
  550.             if (is_object($this->cursor))
  551.             {
  552.                 // Avoid warning if result already freed by third-party library
  553.                 @$this->freeResult();
  554.             }
  555.             $memoryBefore memory_get_usage();
  556.         }
  557.  
  558.         // Execute the query. Error suppression is used here to prevent warnings/notices that the connection has been lost.
  559.         $this->cursor = @mysqli_query($this->connection$query);
  560.  
  561.         if ($this->debug)
  562.         {
  563.             $this->timings[microtime(true);
  564.             if (defined('DEBUG_BACKTRACE_IGNORE_ARGS'))
  565.             {
  566.                 $this->callStacks[debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
  567.             }
  568.             else
  569.             {
  570.                 $this->callStacks[debug_backtrace();
  571.             }
  572.             $this->callStacks[count($this->callStacks1][0]['memory'array($memoryBeforememory_get_usage()is_object($this->cursor$this->getNumRows(null);
  573.         }
  574.  
  575.         // If an error occurred handle it.
  576.         if (!$this->cursor)
  577.         {
  578.             $this->errorNum = (int) mysqli_errno($this->connection);
  579.             $this->errorMsg = (string) mysqli_error($this->connection' SQL=' $query;
  580.  
  581.             // Check if the server was disconnected.
  582.             if (!$this->connected())
  583.             {
  584.                 try
  585.                 {
  586.                     // Attempt to reconnect.
  587.                     $this->connection = null;
  588.                     $this->connect();
  589.                 }
  590.                 // If connect fails, ignore that exception and throw the normal exception.
  591.                 catch (RuntimeException $e)
  592.                 {
  593.                     JLog::add(JText::sprintf('JLIB_DATABASE_QUERY_FAILED'$this->errorNum$this->errorMsg)JLog::ERROR'databasequery');
  594.                     throw new RuntimeException($this->errorMsg$this->errorNum);
  595.                 }
  596.  
  597.                 // Since we were able to reconnect, run the query again.
  598.                 return $this->execute();
  599.             }
  600.             // The server was not disconnected.
  601.             else
  602.             {
  603.                 JLog::add(JText::sprintf('JLIB_DATABASE_QUERY_FAILED'$this->errorNum$this->errorMsg)JLog::ERROR'databasequery');
  604.                 throw new RuntimeException($this->errorMsg$this->errorNum);
  605.             }
  606.         }
  607.  
  608.         return $this->cursor;
  609.     }
  610.  
  611.     /**
  612.      * Renames a table in the database.
  613.      *
  614.      * @param   string  $oldTable  The name of the table to be renamed
  615.      * @param   string  $newTable  The new name for the table.
  616.      * @param   string  $backup    Not used by MySQL.
  617.      * @param   string  $prefix    Not used by MySQL.
  618.      *
  619.      * @return  JDatabaseDriverMysqli  Returns this object to support chaining.
  620.      *
  621.      * @since   12.2
  622.      * @throws  RuntimeException
  623.      */
  624.     public function renameTable($oldTable$newTable$backup null$prefix null)
  625.     {
  626.         $this->setQuery('RENAME TABLE ' $oldTable ' TO ' $newTable)->execute();
  627.  
  628.         return $this;
  629.     }
  630.  
  631.     /**
  632.      * Select a database for use.
  633.      *
  634.      * @param   string  $database  The name of the database to select for use.
  635.      *
  636.      * @return  boolean  True if the database was successfully selected.
  637.      *
  638.      * @since   12.1
  639.      * @throws  RuntimeException
  640.      */
  641.     public function select($database)
  642.     {
  643.         $this->connect();
  644.  
  645.         if (!$database)
  646.         {
  647.             return false;
  648.         }
  649.  
  650.         if (!mysqli_select_db($this->connection$database))
  651.         {
  652.             throw new RuntimeException('Could not connect to database.');
  653.         }
  654.  
  655.         return true;
  656.     }
  657.  
  658.     /**
  659.      * Set the connection to use UTF-8 character encoding.
  660.      *
  661.      * @return  boolean  True on success.
  662.      *
  663.      * @since   12.1
  664.      */
  665.     public function setUTF()
  666.     {
  667.         $this->connect();
  668.  
  669.         return $this->connection->set_charset('utf8');
  670.     }
  671.  
  672.     /**
  673.      * Method to commit a transaction.
  674.      *
  675.      * @param   boolean  $toSavepoint  If true, commit to the last savepoint.
  676.      *
  677.      * @return  void 
  678.      *
  679.      * @since   12.2
  680.      * @throws  RuntimeException
  681.      */
  682.     public function transactionCommit($toSavepoint false)
  683.     {
  684.         $this->connect();
  685.  
  686.         if (!$toSavepoint || $this->transactionDepth <= 1)
  687.         {
  688.             if ($this->setQuery('COMMIT')->execute())
  689.             {
  690.                 $this->transactionDepth = 0;
  691.             }
  692.  
  693.             return;
  694.         }
  695.  
  696.         $this->transactionDepth--;
  697.     }
  698.  
  699.     /**
  700.      * Method to roll back a transaction.
  701.      *
  702.      * @param   boolean  $toSavepoint  If true, rollback to the last savepoint.
  703.      *
  704.      * @return  void 
  705.      *
  706.      * @since   12.2
  707.      * @throws  RuntimeException
  708.      */
  709.     public function transactionRollback($toSavepoint false)
  710.     {
  711.         $this->connect();
  712.  
  713.         if (!$toSavepoint || $this->transactionDepth <= 1)
  714.         {
  715.             if ($this->setQuery('ROLLBACK')->execute())
  716.             {
  717.                 $this->transactionDepth = 0;
  718.             }
  719.  
  720.             return;
  721.         }
  722.  
  723.         $savepoint 'SP_' ($this->transactionDepth - 1);
  724.         $this->setQuery('ROLLBACK TO SAVEPOINT ' $this->quoteName($savepoint));
  725.  
  726.         if ($this->execute())
  727.         {
  728.             $this->transactionDepth--;
  729.         }
  730.     }
  731.  
  732.     /**
  733.      * Method to initialize a transaction.
  734.      *
  735.      * @param   boolean  $asSavepoint  If true and a transaction is already active, a savepoint will be created.
  736.      *
  737.      * @return  void 
  738.      *
  739.      * @since   12.2
  740.      * @throws  RuntimeException
  741.      */
  742.     public function transactionStart($asSavepoint false)
  743.     {
  744.         $this->connect();
  745.  
  746.         if (!$asSavepoint || !$this->transactionDepth)
  747.         {
  748.             if ($this->setQuery('START TRANSACTION')->execute())
  749.             {
  750.                 $this->transactionDepth = 1;
  751.             }
  752.  
  753.             return;
  754.         }
  755.  
  756.         $savepoint 'SP_' $this->transactionDepth;
  757.         $this->setQuery('SAVEPOINT ' $this->quoteName($savepoint));
  758.  
  759.         if ($this->execute())
  760.         {
  761.             $this->transactionDepth++;
  762.         }
  763.     }
  764.  
  765.     /**
  766.      * Method to fetch a row from the result set cursor as an array.
  767.      *
  768.      * @param   mixed  $cursor  The optional result set cursor from which to fetch the row.
  769.      *
  770.      * @return  mixed  Either the next row from the result set or false if there are no more rows.
  771.      *
  772.      * @since   12.1
  773.      */
  774.     protected function fetchArray($cursor null)
  775.     {
  776.         return mysqli_fetch_row($cursor $cursor $this->cursor);
  777.     }
  778.  
  779.     /**
  780.      * Method to fetch a row from the result set cursor as an associative array.
  781.      *
  782.      * @param   mixed  $cursor  The optional result set cursor from which to fetch the row.
  783.      *
  784.      * @return  mixed  Either the next row from the result set or false if there are no more rows.
  785.      *
  786.      * @since   12.1
  787.      */
  788.     protected function fetchAssoc($cursor null)
  789.     {
  790.         return mysqli_fetch_assoc($cursor $cursor $this->cursor);
  791.     }
  792.  
  793.     /**
  794.      * Method to fetch a row from the result set cursor as an object.
  795.      *
  796.      * @param   mixed   $cursor  The optional result set cursor from which to fetch the row.
  797.      * @param   string  $class   The class name to use for the returned row object.
  798.      *
  799.      * @return  mixed   Either the next row from the result set or false if there are no more rows.
  800.      *
  801.      * @since   12.1
  802.      */
  803.     protected function fetchObject($cursor null$class 'stdClass')
  804.     {
  805.         return mysqli_fetch_object($cursor $cursor $this->cursor$class);
  806.     }
  807.  
  808.     /**
  809.      * Method to free up the memory used for the result set.
  810.      *
  811.      * @param   mixed  $cursor  The optional result set cursor from which to fetch the row.
  812.      *
  813.      * @return  void 
  814.      *
  815.      * @since   12.1
  816.      */
  817.     protected function freeResult($cursor null)
  818.     {
  819.         mysqli_free_result($cursor $cursor $this->cursor);
  820.         if (($cursor|| ($cursor === $this->cursor))
  821.         {
  822.             $this->cursor = null;
  823.         }
  824.     }
  825.  
  826.     /**
  827.      * Unlocks tables in the database.
  828.      *
  829.      * @return  JDatabaseDriverMysqli  Returns this object to support chaining.
  830.      *
  831.      * @since   12.1
  832.      * @throws  RuntimeException
  833.      */
  834.     public function unlockTables()
  835.     {
  836.         $this->setQuery('UNLOCK TABLES')->execute();
  837.  
  838.         return $this;
  839.     }
  840.  
  841.     /**
  842.      * Internal function to check if profiling is available
  843.      *
  844.      * @return  boolean 
  845.      *
  846.      * @since 3.1.3
  847.      */
  848.     private function hasProfiling()
  849.     {
  850.         try
  851.         {
  852.             $res mysqli_query($this->connection"SHOW VARIABLES LIKE 'have_profiling'");
  853.             $row mysqli_fetch_assoc($res);
  854.  
  855.             return isset($row);
  856.         }
  857.         catch (Exception $e)
  858.         {
  859.             return false;
  860.         }
  861.     }
  862. }

Documentation generated on Tue, 19 Nov 2013 15:09:16 +0100 by phpDocumentor 1.4.3