Commit 48f1cf998fb43a77ce140f91cb4a8047d6e7e6aa
- Diff rendering mode:
- inline
- side by side
.gitignore
(0 / 1)
|   | |||
| 1 | 1 | *~ | |
| 2 | 2 | doc | |
| 3 | Db/PostgreSQL.php |
Db.php
(9 / 0)
|   | |||
| 14 | 14 | $_connection, | |
| 15 | 15 | $_persistent, | |
| 16 | 16 | $_host, | |
| 17 | $_port, | ||
| 17 | 18 | $_user, | |
| 18 | 19 | $_pass, | |
| 19 | 20 | $_base, | |
| … | … | ||
| 28 | 28 | $this->_connection = null; | |
| 29 | 29 | if (isset($db_params['persistent'])) | |
| 30 | 30 | $this->_persistent = $db_params['persistent']; | |
| 31 | else | ||
| 32 | $this->_persistent = null; | ||
| 31 | 33 | if (isset($db_params['host'])) $this->_host = $db_params['host']; | |
| 34 | else $this->_host = null; | ||
| 35 | if (isset($db_params['port'])) $this->_port = $db_params['port']; | ||
| 36 | else $this->_port = null; | ||
| 32 | 37 | if (isset($db_params['user'])) $this->_user = $db_params['user']; | |
| 38 | else $this->_user = null; | ||
| 33 | 39 | if (isset($db_params['pass'])) $this->_pass = $db_params['pass']; | |
| 40 | else $this->_pass = null; | ||
| 34 | 41 | if (isset($db_params['base'])) $this->_base = $db_params['base']; | |
| 42 | else $this->_base = null; | ||
| 35 | 43 | $this->_query = null; | |
| 36 | 44 | $this->_numberOfQueries = 0; | |
| 37 | 45 | $this->_results = null; |
Db/MySQL.php
(4 / 0)
|   | |||
| 13 | 13 | public function __construct ($db_params) | |
| 14 | 14 | { | |
| 15 | 15 | parent::__construct($db_params); | |
| 16 | if ($this->_port != null) { | ||
| 17 | $this->_host .= ':'.$this->_port; | ||
| 18 | $this->_port = null; | ||
| 19 | } | ||
| 16 | 20 | $this->connect(); | |
| 17 | 21 | } | |
| 18 | 22 |
Db/PostgreSQL.php
(108 / 0)
|   | |||
| 1 | <?php | ||
| 2 | /* | ||
| 3 | Belokan Micro Framework | ||
| 4 | Licensed under GNU GPL | ||
| 5 | http://gitorious.org/projects/belokan | ||
| 6 | --- | ||
| 7 | Belokan/Db/PostgreSQL.php: | ||
| 8 | PostgreSQL database class | ||
| 9 | */ | ||
| 10 | |||
| 11 | class Belokan_Db_PostgreSQL extends Belokan_Db { | ||
| 12 | |||
| 13 | public function __construct ($db_params) | ||
| 14 | { | ||
| 15 | parent::__construct($db_params); | ||
| 16 | $this->connect(); | ||
| 17 | } | ||
| 18 | |||
| 19 | public function connect () | ||
| 20 | { | ||
| 21 | $con = ''; | ||
| 22 | if ($this->_host != null) $con .= ' host='.$this->_host; | ||
| 23 | if ($this->_port != null) $con .= ' port='.$this->_port; | ||
| 24 | if ($this->_base != null) $con .= ' dbname='.$this->_base; | ||
| 25 | if ($this->_user != null) $con .= ' user='.$this->_user; | ||
| 26 | if ($this->_pass != null) $con .= ' password='.$this->_pass; | ||
| 27 | |||
| 28 | if (empty($con)) return; | ||
| 29 | $con = substr($con, 1); | ||
| 30 | |||
| 31 | if ($this->_persistent) | ||
| 32 | $this->_connection = pg_pconnect($con); | ||
| 33 | else | ||
| 34 | $this->_connection = pg_connect($con); | ||
| 35 | } | ||
| 36 | |||
| 37 | public function execute () | ||
| 38 | { | ||
| 39 | $this->_results = pg_query($this->_connection, $this->_query); | ||
| 40 | $this->_numberOfQueries++; | ||
| 41 | return $this->_results; | ||
| 42 | } | ||
| 43 | |||
| 44 | public function execQuery ($query, $update_query=false) | ||
| 45 | { | ||
| 46 | if ($update_query == true) $this->_query = $query; | ||
| 47 | $this->_numberOfQueries++; | ||
| 48 | return pg_query($this->_connection, $query); | ||
| 49 | } | ||
| 50 | |||
| 51 | public function seek ($row) | ||
| 52 | { | ||
| 53 | pg_result_seek($this->_results, $row); | ||
| 54 | return pg_fetch_row($this->_results); | ||
| 55 | } | ||
| 56 | |||
| 57 | public function lastAutoIncrementValue ($table, $ai_col) | ||
| 58 | { | ||
| 59 | $laiv = pg_query($this->_connection, | ||
| 60 | "SELECT currval(pg_get_serial_sequence('".$table."', '".$ai_col."'));"); | ||
| 61 | $this->_numberOfQueries++; | ||
| 62 | $laiv = pg_fetch_array($laiv, null, PGSQL_NUM); | ||
| 63 | return $laiv[0]; | ||
| 64 | } | ||
| 65 | |||
| 66 | public function fetchRows ($fetch_object=false) | ||
| 67 | { | ||
| 68 | if ($this->_results == null) return null; | ||
| 69 | $this->_rows = array(); | ||
| 70 | if ($fetch_object) | ||
| 71 | while ($row = pg_fetch_object($this->_results)) | ||
| 72 | $this->_rows[] = $row; | ||
| 73 | else | ||
| 74 | while ($row = pg_fetch_array($this->_results)) | ||
| 75 | $this->_rows[] = $row; | ||
| 76 | return $this->_rows; | ||
| 77 | } | ||
| 78 | |||
| 79 | public function fetchRow ($fetch_object=false) | ||
| 80 | { | ||
| 81 | if ($this->_results == null) return null; | ||
| 82 | if ($fetch_object) return pg_fetch_object($this->_results); | ||
| 83 | return pg_fetch_array($this->_results); | ||
| 84 | } | ||
| 85 | |||
| 86 | public function numberOfRows () | ||
| 87 | { | ||
| 88 | if (strtolower(substr($this->_query, 0, 6)) == 'select' && $this->_results != null) | ||
| 89 | return mysql_num_rows($this->_results); | ||
| 90 | else if ($this->_results === true) | ||
| 91 | return $this->affectedRows(); | ||
| 92 | return null; | ||
| 93 | } | ||
| 94 | |||
| 95 | public function affectedRows () | ||
| 96 | { | ||
| 97 | if (in_array(strtolower(substr($this->_query, 0, 7)), array('insert ', 'update ', 'delete '))) | ||
| 98 | return pg_affected_rows($this->_results); | ||
| 99 | return null; | ||
| 100 | } | ||
| 101 | |||
| 102 | public function freeResults () | ||
| 103 | { | ||
| 104 | if (strtolower(substr($this->_query, 0, 6)) == 'select' && $this->_results != null) | ||
| 105 | pg_free_result($this->_results); | ||
| 106 | } | ||
| 107 | |||
| 108 | } |

