Source for file dbapi.mysqli.class.inc.php

Documentation is available at dbapi.mysqli.class.inc.php

  1. <?php
  2. require_once('dbapi.abstract.class.inc.php');
  3.  
  4. class DBAPI extends DBAPI_abstract {
  5.  
  6.     public $conn;
  7.     public $config;
  8.     public $isConnected;
  9.     
  10.     protected $parent// Usually the $modx global
  11.     
  12.     protected $host$dbase// Holds host and db name if connected.
  13.  
  14.     // -----
  15.     // SETUP 
  16.     // -----
  17.  
  18.     protected function initDataTypes({
  19.         $this->dataTypes['numeric'array (
  20.             'INT',
  21.             'INTEGER',
  22.             'TINYINT',
  23.             'BOOLEAN',
  24.             'DECIMAL',
  25.             'DEC',
  26.             'NUMERIC',
  27.             'FLOAT',
  28.             'DOUBLE PRECISION',
  29.             'REAL',
  30.             'SMALLINT',
  31.             'MEDIUMINT',
  32.             'BIGINT',
  33.             'BIT'
  34.         );
  35.         $this->dataTypes['string'array (
  36.             'CHAR',
  37.             'VARCHAR',
  38.             'BINARY',
  39.             'VARBINARY',
  40.             'TINYBLOB',
  41.             'BLOB',
  42.             'MEDIUMBLOB',
  43.             'LONGBLOB',
  44.             'TINYTEXT',
  45.             'TEXT',
  46.             'MEDIUMTEXT',
  47.             'LONGTEXT',
  48.             'ENUM',
  49.             'SET'
  50.         );
  51.         $this->dataTypes['date'array (
  52.             'DATE',
  53.             'DATETIME',
  54.             'TIMESTAMP',
  55.             'TIME',
  56.             'YEAR'
  57.         );
  58.     }
  59.  
  60.     // -------
  61.     // CONNECT
  62.     // -------
  63.  
  64.     protected function make_connection($host$uid$pwd{
  65.           return $this->conn = mysqli_connect($host$uid$pwd);
  66.     }
  67.  
  68.     protected function make_persistent_connection($host$uid$pwd{
  69.           return $this->conn = mysqli_connect('p:'.$host$uid$pwd);
  70.     }
  71.  
  72.     protected function set_charset($charset{
  73.         return mysqli_set_charset($this->conn$charset);
  74.     }
  75.  
  76.     protected function select_db($dbname{
  77.           return mysqli_select_db($this->conn$dbname);
  78.     }
  79.  
  80.     // ----------
  81.     // DISCONNECT
  82.     // ----------
  83.  
  84.     public function disconnect({
  85.           @mysqli_close($this->conn);
  86.     }
  87.  
  88.     // ----------------
  89.     // CLIPPERCMS DBAPI
  90.     // ----------------
  91.  
  92.     public function getAffectedRows({
  93.         return mysqli_affected_rows($this->conn);
  94.     }
  95.  
  96.     public function getLastError($return_number false{
  97.         if ($return_number{
  98.               $err mysqli_errno($this->conn);
  99.         else {
  100.               $err mysqli_error($this->conn);
  101.         }
  102.         return $err;
  103.     }
  104.  
  105.     public function getTableMetaData($table{
  106.         $metadata false;
  107.         if (!empty ($table)) {
  108.             $sql "SHOW FIELDS FROM $table";
  109.             if ($ds $this->query($sql)) {
  110.                 while ($row $this->getRow($ds)) {
  111.                     $fieldName $row['Field'];
  112.                     $metadata[$fieldName$row;
  113.                 }
  114.             }
  115.         }
  116.         return $metadata;
  117.     }
  118.  
  119.     public function getVersion({
  120.          return mysqli_get_server_info($this->conn);
  121.     }
  122.     
  123.     public function is_handle($var{
  124.         return is_object($var);
  125.     }
  126.     
  127.     public function freeResult($rs{
  128.         mysqli_free_result($rs);
  129.     }
  130.     
  131.     public function tables_present($prefix{
  132.         return (bool)$this->getValue("SELECT COUNT(*) FROM information_schema.tables
  133.                                  WHERE `table_schema` = '{$this->dbase}' AND `table_name` = '{$prefix}site_content'");
  134.     }
  135.  
  136.     public function table_engine($table) {
  137.         return $this->getValue('SELECT ENGINE FROM information_schema.TABLES where TABLE_SCHEMA = \''.$this->dbase.'\'');
  138.     }
  139.  
  140.     // -------------------------------------------
  141.     // LOW LEVEL RBDMS-SPECIFIC INTERNAL FUNCTIONS
  142.     // -------------------------------------------
  143.     protected function _escape($s) {
  144.           return mysqli_real_escape_string($this->conn$s);
  145.     }
  146.  
  147.     protected function _query($sql) {
  148.         return mysqli_query($this->conn$sql);
  149.     }
  150.  
  151.     protected function _recordcount($rs) {
  152.         return mysqli_num_rows($rs);
  153.     }
  154.  
  155.     protected function _getRowAssoc($rs) {
  156.           return mysqli_fetch_assoc($rs);
  157.     }
  158.  
  159.     protected function _getRowNumeric($rs) {
  160.           return mysqli_fetch_row($rs);
  161.     }
  162.  
  163.     protected function _getRowBoth($rs) {
  164.           return mysqli_fetch_array($rs, MYSQLI_BOTH);
  165.     }
  166.  
  167.     protected function _getColumnNames($rs) {
  168.         if ($rs) {
  169.             $fields = mysqli_fetch_fields($rs);
  170.             $names = array ();
  171.             foreach($fields as $field) {
  172.                 $names[] = $field->name;
  173.             }
  174.             return $names;
  175.         }
  176.     }
  177.  
  178.     protected function _getInsertId() {
  179.         return mysqli_insert_id($this->conn);
  180.     }
  181.  

Documentation generated on Fri, 21 Jun 2013 12:37:01 +0100 by phpDocumentor 1.4.4