Source for file ConnectDBMysqli.class.php

Documentation is available at ConnectDBMysqli.class.php

  1. <?php
  2. /**
  3.  * Class ConnectDBMysqli, database connectivity class based on Mysqli Extension
  4.  *
  5.  * All database connectivity in whole chat have to use this class to communicate whith the DB
  6.  *
  7.  * LICENSE: CREATIVE COMMONS PUBLIC LICENSE  "Namensnennung — Nicht-kommerziell 2.0"
  8.  *
  9.  * @copyright  2009 <SEDesign />
  10.  * @license    http://creativecommons.org/licenses/by-nc/2.0/de/
  11.  * @version    $3.0.6$
  12.  * @link       http://www.sedesign.de/de_produkte_chat-v3.html
  13.  * @since      File available since Beta 1.0
  14.  */
  15.  
  16. class ConnectDBMysqli extends EtChatConfig{
  17.     
  18.     /**
  19.     * MySQLi Obj with DB connect
  20.     * @var MySQLi 
  21.     */
  22.     protected $_connid;
  23.     
  24.     /**
  25.     * last inserted id in the db after any sql-manipulation-statements
  26.     * @var int 
  27.     */
  28.     public $lastId;
  29.     
  30.     /**
  31.     * Constructor,  creates a db connectivity
  32.     *
  33.     * @uses MySQLi object creation
  34.     * @return void 
  35.     */
  36.     public function __construct (){
  37.     
  38.         // call parent Constructor from class EtChatConfig
  39.         parent::__construct();
  40.     
  41.         $this->_connid = new mysqli($this->_sqlhost$this->_sqluser$this->_sqlpass$this->_database);
  42.  
  43.         // check connection 
  44.         if ($this->_connid->connect_error{
  45.             printf("Connect failed: %s\n"mysqli_connect_error());
  46.             return false;
  47.         }
  48.  
  49.     }
  50.     
  51.     /**
  52.     * for making sql-select-queries
  53.     *
  54.     * @param  string $sql 
  55.     * @uses MySQLi::query()
  56.     * @uses MySQLi::fetch_array()
  57.     * @return array, with the datasets
  58.     */
  59.     public function sqlGet($sql){
  60.     
  61.         // set query
  62.         $result $this->_connid->query($sql);
  63.         
  64.         $a=0;
  65.  
  66.         while($row $result->fetch_array(MYSQLI_NUM)) {
  67.             $b=0;
  68.             foreach ($row as $field{
  69.                 $resultArray[$a][$b]=$field;
  70.                 $b++;
  71.             }
  72.             $a++;
  73.         }
  74.         
  75.         if (!is_array($resultArray)) return 0;
  76.         return $resultArray;
  77.     }
  78.     
  79.     /**
  80.     * for making sql-manipulation-queries
  81.     *
  82.     * @param  string $sql 
  83.     * @uses MySQLi::query()
  84.     * @uses MySQLi::$insert_id
  85.     * @return int, number of manipulated datasets
  86.     */
  87.     public function sqlSet($sql){
  88.         
  89.         // set query
  90.         $datasets $this->_connid->query($sql);
  91.         
  92.         // get last table ID after manipulation
  93.         $this->lastId = $this->_connid->insert_id;
  94.         return $datasets;
  95.     }
  96.     
  97.     /**
  98.     * close db connection
  99.     *
  100.     * @uses MySQLi::close()
  101.     * @return void 
  102.     */
  103.     public function close(){
  104.         $this->_connid->close();
  105.     }
  106. }

Documentation generated on Tue, 22 Dec 2009 09:42:47 +0100 by phpDocumentor 1.4.1