summaryrefslogtreecommitdiffstats
path: root/codebase/DataStorage/PDODBDataWrapper.php
diff options
context:
space:
mode:
authorKirylka <kirylanoshko@gmail.com>2015-03-31 17:56:47 +0300
committerKirylka <kirylanoshko@gmail.com>2015-03-31 17:56:47 +0300
commitf5f99c335707d9b11d40f1eb0f6ddb5a993fd31a (patch)
treed9c0d3532ec9f0f2fb68e31d2611282ae0642181 /codebase/DataStorage/PDODBDataWrapper.php
parent458f0aead573842f1df00ce2ae00334c27f66585 (diff)
downloadconnector-php-f5f99c335707d9b11d40f1eb0f6ddb5a993fd31a.zip
connector-php-f5f99c335707d9b11d40f1eb0f6ddb5a993fd31a.tar.gz
connector-php-f5f99c335707d9b11d40f1eb0f6ddb5a993fd31a.tar.bz2
Creating a new connector for yii2.
Diffstat (limited to 'codebase/DataStorage/PDODBDataWrapper.php')
-rw-r--r--codebase/DataStorage/PDODBDataWrapper.php82
1 files changed, 82 insertions, 0 deletions
diff --git a/codebase/DataStorage/PDODBDataWrapper.php b/codebase/DataStorage/PDODBDataWrapper.php
new file mode 100644
index 0000000..5a08e57
--- /dev/null
+++ b/codebase/DataStorage/PDODBDataWrapper.php
@@ -0,0 +1,82 @@
+<?php
+
+namespace DHTMLX\Connector\DataStorage;
+
+/*! 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) {
+ $message = $this->connection->errorInfo();
+ throw new Exception("PDO - sql execution failed\n".$message[2]);
+ }
+
+ return new PDOResultSet($res);
+ }
+
+ protected function select_query($select,$from,$where,$sort,$start,$count){
+ if (!$from)
+ return $select;
+
+ $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 tables_list() {
+ $result = $this->query("SHOW TABLES");
+ if ($result===false) throw new Exception("MySQL operation failed\n".mysql_error($this->connection));
+
+ $tables = array();
+ while ($table = $result->next()) {
+ $tables[] = $table[0];
+ }
+ return $tables;
+ }
+
+ public function fields_list($table) {
+ $result = $this->query("SHOW COLUMNS FROM `".$table."`");
+ if ($result===false) throw new Exception("MySQL operation failed\n".mysql_error($this->connection));
+
+ $fields = array();
+ $id = "";
+ while ($field = $result->next()) {
+ if ($field['Key'] == "PRI")
+ $id = $field["Field"];
+ else
+ $fields[] = $field["Field"];
+ }
+ return array("fields" => $fields, "key" => $id );
+ }
+
+ public function get_next($res){
+ $data = $res->next();
+ return $data;
+ }
+
+ public 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);
+ }
+
+} \ No newline at end of file