Skip to content

Commit 78aad87

Browse files
Added db wrapper for codeigniter version 3.
1 parent 458f0ae commit 78aad87

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

codebase/db_phpci.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,16 +44,24 @@ public function escape_name($data){
4444
}
4545

4646
class PHPCIResultSet{
47+
private $is_result_done = false;
4748
private $res;
4849
private $start;
4950
private $count;
5051

5152
public function __construct($res){
53+
if(is_bool($res)) {
54+
$this->$is_result_done = true;
55+
return $this;
56+
}
5257
$this->res = $res;
5358
$this->start = $res->current_row;
54-
$this->count = $res->num_rows;
59+
$this->count = $res->num_rows();
5560
}
5661
public function next(){
62+
if($this->is_result_done)
63+
return null;
64+
5765
if ($this->start != $this->count){
5866
return $this->res->row($this->start++,'array');
5967
} else {

codebase/db_phpci2.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
/*
3+
@author dhtmlx.com
4+
@license GPL, see license.txt
5+
*/
6+
require_once("db_common.php");
7+
8+
/*! Implementation of DataWrapper for PDO
9+
10+
if you plan to use it for Oracle - use Oracle connection type instead
11+
**/
12+
class PHPCIDBDataWrapper extends DBDataWrapper{
13+
private $last_result;//!< store result or last operation
14+
15+
public function query($sql){
16+
LogMaster::log($sql);
17+
18+
$res=$this->connection->query($sql);
19+
if ($res===false) {
20+
throw new Exception("CI - sql execution failed");
21+
}
22+
23+
if (is_object($res))
24+
return new PHPCIResultSet($res);
25+
return new ArrayQueryWrapper(array());
26+
}
27+
28+
public function get_next($res){
29+
$data = $res->next();
30+
return $data;
31+
}
32+
33+
public function get_new_id(){
34+
return $this->connection->insert_id();
35+
}
36+
37+
public function escape($str){
38+
return $this->connection->escape_str($str);
39+
}
40+
41+
public function escape_name($data){
42+
return $this->connection->protect_identifiers($data);
43+
}
44+
}
45+
46+
class PHPCIResultSet{
47+
private $res;
48+
private $start;
49+
private $count;
50+
51+
public function __construct($res){
52+
$this->res = $res;
53+
$this->start = $res->current_row;
54+
$this->count = $res->num_rows;
55+
}
56+
public function next(){
57+
if ($this->start != $this->count){
58+
return $this->res->row($this->start++,'array');
59+
} else {
60+
$this->res->free_result();
61+
return null;
62+
}
63+
}
64+
}
65+
?>

0 commit comments

Comments
 (0)