PhpMyObject
[ class tree: PhpMyObject ] [ index: PhpMyObject ] [ all elements ]

Source for file PMO_Dbms_Pdo.php

Documentation is available at PMO_Dbms_Pdo.php

  1. <?php
  2. /**
  3.  * This file contains the PMO_Dbms_Pdo driver class.
  4.  *
  5.  * This file is part of the PhpMyObject project,
  6.  * an Object-Relational Mapping (ORM) system.
  7.  * 
  8.  * For questions, help, comments, discussion, etc., please join our
  9.  * forum at {@link http://www.developpez.net/forums/forumdisplay.php?f=770}
  10.  * or our mailing list at {@link http://groups.google.com/group/pmo-dev}.
  11.  *
  12.  * PhpMyObject is free software: you can redistribute it and/or modify
  13.  * it under the terms of the GNU General Public License as published by
  14.  * the Free Software Foundation, either version 3 of the License, or
  15.  * (at your option) any later version.
  16.  *
  17.  * This program is distributed in the hope that it will be useful,
  18.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.    See the
  20.  * GNU General Public License for more details.
  21.  *
  22.  * You should have received a copy of the GNU General Public License
  23.  * along with this program.  If not, see {@link http://www.gnu.org/licenses/}.
  24.  *
  25.  * @package        PhpMyObject
  26.  * @subpackage PMO_Core
  27.  * @author        Nicolas Boiteux <nicolas_boiteux@yahoo.fr>
  28.  * @link            http://pmo.developpez.com/
  29.  * @since        PhpMyObject v0.1
  30.  * @version        $Revision: $
  31.  * @copyright    Copyright (C) 2007-2008 Nicolas Boiteux
  32.  * @license        GPLv3 {@link http://www.gnu.org/licenses/gpl}
  33.  * @filesource
  34.  *
  35.  */ 
  36.  
  37. /**
  38.  * This class implements a PDO driver.
  39.  * 
  40.  * @package        PhpMyObject
  41.  * @subpackage PMO_Core
  42.  */
  43. class PMO_Dbms_Pdo extends PMO_MyDbms {
  44.  
  45.     public function __construct(PDO $pdo NULL{
  46.         if(isset($pdo))
  47.             $this->setDB($pdo);
  48.     }
  49.     
  50.     public function connect(array $authdb){
  51.         $this->setDB(new PDO("$authdb[pdodriver]:host=$authdb[host];dbname=$authdb[base]"$authdb['user']$authdb['pass']));
  52.         $this->getDB()->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
  53.     }
  54.     
  55.     public function __destruct({
  56.         $this->setDB(NULL);
  57.     }
  58.  
  59.     public function query($query){
  60.         $this->result $this->getDB()->prepare($query);
  61.         if(!$this->result->execute()){
  62.             $errorinfo $this->result->errorInfo();
  63.             throw new Exception("Error: SQL ".$errorinfo[0]." ".$errorinfo[2]);    
  64.         else {
  65.             return TRUE;
  66.         }
  67.     }
  68.  
  69.     public function fetchArray({
  70.         return $this->result->fetch(PDO::FETCH_ASSOC);
  71.     }
  72.  
  73.     public function getTableDesc($table{
  74.         $sql sprintf('DESC %s ;'addslashes($table));
  75.         $this->query($sql);
  76.         
  77.         while($dbresult $this->fetchArray()){
  78.             $tmparray[array("Field"=>$dbresult['Field']
  79.                                 "Type" => $this->translateType($dbresult['Type'])
  80.                                 "Null" => $dbresult['Null']
  81.                                 "Key"=>$dbresult['Key']
  82.                                 "Default"=>$dbresult['Default']
  83.                                 "Extra"=>$dbresult['Extra'],
  84.                                 "Perm"=>"rw");
  85.         }
  86.         return $tmparray;
  87.     }
  88.     
  89.     public function getLastId({
  90.         return $this->getDB()->lastInsertId();
  91.     }
  92.  
  93.     /**
  94.      * begin a transaction with Dbms
  95.      * only with pdo driver
  96.      */
  97.     public function beginTransaction(){
  98.         return $this->getDb()->beginTransaction();
  99.     }
  100.  
  101.     /**
  102.      * commit the transaction with Dbms
  103.      * only with pdo driver
  104.      */    
  105.     public function commit(){
  106.         return $this->getDb()->commit();
  107.     }    
  108.     
  109.     /**
  110.      * rollback the transaction with Dbms
  111.      * only with pdo driver
  112.      */    
  113.     public function rollback(){
  114.         return $this->getDb()->rollback();
  115.     }
  116.     
  117. }
  118. ?>

Documentation generated on Wed, 15 Oct 2008 09:16:11 -0400 by phpDocumentor 1.4.1