Source for file ConnectDB.class.php

Documentation is available at ConnectDB.class.php

  1. <?php
  2. /**
  3.  * Class ConnectDB, database connectivity class based on PDO 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 Alpha 1.0
  14.  */
  15.  
  16. class ConnectDB extends EtChatConfig{
  17.     
  18.     /**
  19.     * PDO Obj with DB connect
  20.     * @var PDO 
  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 PDO object creation
  34.     * @return void 
  35.     */
  36.     public function __construct (){
  37.     
  38.         // call parent Constructor from class EtChatConfig
  39.         parent::__construct();
  40.     
  41.         try 
  42.         {    
  43.             $this->_connid = new PDO("{$this->_usedDatabase}:host={$this->_sqlhost};dbname=".$this->_database$this->_sqluser$this->_sqlpass);
  44.         }
  45.         catch(PDOException $e)
  46.         {
  47.             echo "ERROR: " . $e->getMessage();
  48.             echo "<br /><h3>Bitte editieren Sie die config.php und tragen Sie dort die geforderten Parameter ein. Danach machen Sie weiter mit der Installationsroutine. Mehr dazu finden Sie unter install.txt !</h3>";
  49.         }
  50.     }
  51.     
  52.     /**
  53.     * for making sql-select-queries
  54.     *
  55.     * @param  string $sql 
  56.     * @uses PDO::query()    
  57.     * @uses PDO::errorInfo()
  58.     * @return array, with the datasets
  59.     */
  60.     public function sqlGet($sql){
  61.     
  62.         // set query
  63.         $erg = $this->_connid->query($sql);
  64.         
  65.         // on error
  66.         $error_code=(int)$this->_connid->errorCode();
  67.         if (!empty($error_code)) {
  68.             $arr = $this->_connid->errorInfo();
  69.             print_r($arr);
  70.             echo $sql;
  71.             if ($arr[1]==1146)
  72.                 echo "<br /><h4>Dieser Fehler deutet darauf, dass der ET-Chat nicht ordentlich in die Datenbank installiert wurde.
  73.                 Lesen Sie bitte dazu die readme.txt und nutzen Sie die <a href=\"install/\">Installationsroutine</a>.</h4>";
  74.         }
  75.         
  76.         $resultArray = $erg->fetchAll(PDO::FETCH_NUM);
  77.         
  78.         $erg = null;
  79.         
  80.         if (!isset($resultArray|| empty($resultArray)) return 0;
  81.         return $resultArray;
  82.     }
  83.     
  84.     /**
  85.     * for making sql-manipulation-queries
  86.     *
  87.     * @param  string $sql 
  88.     * @uses PDO::exec()
  89.     * @uses PDO::errorInfo()
  90.     * @uses PDO::lastInsertId()
  91.     * @return int, number of manipulated datasets
  92.     */
  93.     public function sqlSet($sql){
  94.         
  95.         // set query
  96.         $datasets = $this->_connid->exec($sql);
  97.         
  98.         // on error
  99.         $error_code=(int)$this->_connid->errorCode();
  100.         if (!empty($error_code)) {
  101.             $arr = $this->_connid->errorInfo();
  102.             print_r($arr);
  103.             echo $sql;
  104.         }
  105.         
  106.         // get last table ID after manipulation
  107.         $this->lastId = $this->_connid->lastInsertId();
  108.         return $datasets;
  109.     }
  110.     
  111.     /**
  112.     * close db connection
  113.     *
  114.     * @return void
  115.     */
  116.     public function close(){
  117.         $this->_connid=null;
  118.     }

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