diff options
author | Maksim <max@dhtmlx.com> | 2011-07-18 18:21:10 +0300 |
---|---|---|
committer | Maksim <max@dhtmlx.com> | 2011-07-18 18:21:10 +0300 |
commit | 5c2afae6cf595c981155ac68501ac2d1af77db54 (patch) | |
tree | b07de6379fb3eb540df732a57061cafd05288599 /codebase/db_pdo.php | |
download | connector-php-5c2afae6cf595c981155ac68501ac2d1af77db54.zip connector-php-5c2afae6cf595c981155ac68501ac2d1af77db54.tar.gz connector-php-5c2afae6cf595c981155ac68501ac2d1af77db54.tar.bz2 |
* import of php connector v1.2
Diffstat (limited to 'codebase/db_pdo.php')
-rw-r--r-- | codebase/db_pdo.php | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/codebase/db_pdo.php b/codebase/db_pdo.php new file mode 100644 index 0000000..281b23d --- /dev/null +++ b/codebase/db_pdo.php @@ -0,0 +1,69 @@ +<?php +/* + @author dhtmlx.com + @license GPL, see license.txt +*/ +require_once("db_common.php"); +/*! Implementation of DataWrapper for PDO + +if you plan to use it for Oracle - use Oracle connection type instead +**/ +class PDODBDataWrapper extends DBDataWrapper{ + private $last_result;//!< store result or last operation + + public function query($sql){ + LogMaster::log($sql); + + $res=$this->connection->query($sql); + if ($res===false) throw new Exception("PDO - sql execution failed\n".$this->connection->errorInfo()); + + return new PDOResultSet($res); + } + + protected function select_query($select,$from,$where,$sort,$start,$count){ + $sql="SELECT ".$select." FROM ".$from; + if ($where) $sql.=" WHERE ".$where; + if ($sort) $sql.=" ORDER BY ".$sort; + if ($start || $count) { + if ($this->connection->getAttribute(PDO::ATTR_DRIVER_NAME)=="pgsql") + $sql.=" OFFSET ".$start." LIMIT ".$count; + else + $sql.=" LIMIT ".$start.",".$count; + } + return $sql; + } + + + public function get_next($res){ + $data = $res->next(); + return $data; + } + + protected function get_new_id(){ + return $this->connection->lastInsertId(); + } + + public function escape($str){ + $res=$this->connection->quote($str); + if ($res===false) //not supported by pdo driver + return str_replace("'","''",$str); + return substr($res,1,-1); + } + +} + +class PDOResultSet{ + private $res; + public function __construct($res){ + $this->res = $res; + } + public function next(){ + $data = $this->res->fetch(PDO::FETCH_ASSOC); + if (!$data){ + $this->res->closeCursor(); + return null; + } + return $data; + } +} +?>
\ No newline at end of file |