Commit 3978ebba02c69fa227423d89f19df737b40083d7
- Diff rendering mode:
- inline
- side by side
Db.php
(13 / 7)
|   | |||
| 12 | 12 | ||
| 13 | 13 | protected | |
| 14 | 14 | $_connection, | |
| 15 | $_persistent, | ||
| 15 | 16 | $_host, | |
| 16 | 17 | $_user, | |
| 17 | 18 | $_pass, | |
| … | … | ||
| 25 | 25 | public function __construct ($db_params) | |
| 26 | 26 | { | |
| 27 | 27 | $this->_connection = null; | |
| 28 | $this->_host = null; | ||
| 29 | $this->_user = null; | ||
| 30 | $this->_pass = null; | ||
| 31 | $this->_base = null; | ||
| 28 | if (isset($db_params['persistent'])) | ||
| 29 | $this->_persistent = $db_params['persistent']; | ||
| 30 | if (isset($db_params['host'])) $this->_host = $db_params['host']; | ||
| 31 | if (isset($db_params['user'])) $this->_user = $db_params['user']; | ||
| 32 | if (isset($db_params['pass'])) $this->_pass = $db_params['pass']; | ||
| 33 | if (isset($db_params['base'])) $this->_base = $db_params['base']; | ||
| 32 | 34 | $this->_query = null; | |
| 33 | 35 | $this->_numberOfQueries = 0; | |
| 34 | 36 | $this->_results = null; | |
| 35 | 37 | $this->_rows = array(); | |
| 36 | 38 | } | |
| 39 | |||
| 40 | abstract function connect (); | ||
| 37 | 41 | ||
| 38 | abstract function reconnect (); | ||
| 42 | public function reconnect () | ||
| 43 | { | ||
| 44 | if (!$this->isConnected()) $this->connect(); | ||
| 45 | } | ||
| 39 | 46 | ||
| 40 | 47 | public function isConnected () | |
| 41 | 48 | { | |
| … | … | ||
| 119 | 119 | { | |
| 120 | 120 | return $this->_numberOfQueries; | |
| 121 | 121 | } | |
| 122 | |||
| 123 | abstract function freeResults (); | ||
| 124 | 122 | ||
| 125 | 123 | } |
Db/MySQL.php
(16 / 16)
|   | |||
| 13 | 13 | public function __construct ($db_params) | |
| 14 | 14 | { | |
| 15 | 15 | parent::__construct($db_params); | |
| 16 | $this->_host = $db_params['host']; | ||
| 17 | $this->_user = $db_params['user']; | ||
| 18 | $this->_pass = $db_params['pass']; | ||
| 19 | $this->_base = $db_params['base']; | ||
| 20 | |||
| 21 | $this->_connection = mysql_connect($this->_host, $this->_user, $this->_pass); | ||
| 22 | mysql_select_db($this->_base, $this->_connection); | ||
| 16 | $this->connect(); | ||
| 23 | 17 | } | |
| 24 | |||
| 25 | public function reconnect () | ||
| 18 | |||
| 19 | public function connect () | ||
| 26 | 20 | { | |
| 27 | if (!$this->isConnected()) { | ||
| 28 | $this->_connection = mysql_connect($this->_host, $this->_user, $this->_pass); | ||
| 29 | mysql_select_db($this->_base, $this->_connection); | ||
| 30 | } | ||
| 21 | if ($this->_persistent) $this->_connection = mysql_pconnect($this->_host, | ||
| 22 | $this->_user, | ||
| 23 | $this->_pass); | ||
| 24 | else $this->_connection = mysql_connect($this->_host, | ||
| 25 | $this->_user, | ||
| 26 | $this->_pass); | ||
| 27 | mysql_select_db($this->_base, $this->_connection); | ||
| 31 | 28 | } | |
| 32 | 29 | ||
| 33 | 30 | public function execute () | |
| … | … | ||
| 75 | 75 | ||
| 76 | 76 | public function numberOfRows () | |
| 77 | 77 | { | |
| 78 | if (strtolower(substr($this->_query, 0, 6)) == 'select' && $this->_results != null) | ||
| 78 | if (strtolower(substr($this->_query, 0, 6)) == 'select' && | ||
| 79 | $this->_results != null) | ||
| 79 | 80 | return mysql_num_rows($this->_results); | |
| 80 | 81 | else if ($this->_results === true) | |
| 81 | 82 | return $this->affectedRows(); | |
| … | … | ||
| 85 | 85 | ||
| 86 | 86 | public function affectedRows () | |
| 87 | 87 | { | |
| 88 | if (in_array(strtolower(substr($this->_query, 0, 7)), array('insert ', 'update ', 'replace', 'delete '))) | ||
| 88 | if (in_array(strtolower(substr($this->_query, 0, 7)), | ||
| 89 | array('insert ', 'update ', 'replace', 'delete '))) | ||
| 89 | 90 | return mysql_affected_rows($this->_connection); | |
| 90 | 91 | else return null; | |
| 91 | 92 | } | |
| 92 | 93 | ||
| 93 | 94 | public function freeResults () | |
| 94 | 95 | { | |
| 95 | if (substr($this->_query, 0, 6) == 'SELECT' && $this->_results != null) | ||
| 96 | if (strtolower(substr($this->_query, 0, 6)) == 'select' && | ||
| 97 | $this->_results != null) | ||
| 96 | 98 | mysql_free_result($this->_results); | |
| 97 | 99 | } | |
| 98 | 100 |
Db/SQLite.php
(10 / 18)
|   | |||
| 13 | 13 | public function __construct ($db_params) | |
| 14 | 14 | { | |
| 15 | 15 | parent::__construct($db_params); | |
| 16 | $this->_base = $db_params['base']; | ||
| 17 | 16 | if (isset($db_params['dir'])) | |
| 18 | $this->_base = $db_params['dir'].$db_params['base']; | ||
| 19 | else | ||
| 20 | $this->_base = $db_params['base']; | ||
| 21 | |||
| 22 | $this->_connection = sqlite_open($this->_base); | ||
| 17 | $this->_base = $db_params['dir'].$this->_base; | ||
| 18 | $this->connect(); | ||
| 23 | 19 | } | |
| 24 | |||
| 25 | public function reconnect () | ||
| 20 | |||
| 21 | public function connect () | ||
| 26 | 22 | { | |
| 27 | if (!$this->isConnected()) | ||
| 28 | $this->_connection = sqlite_open($this->_base); | ||
| 23 | if ($this->_persistent) $this->_connection = sqlite_popen($this->_base); | ||
| 24 | else $this->_connection = sqlite_open($this->_base); | ||
| 29 | 25 | } | |
| 30 | 26 | ||
| 31 | 27 | public function execute () | |
| … | … | ||
| 72 | 72 | ||
| 73 | 73 | public function numberOfRows () | |
| 74 | 74 | { | |
| 75 | if (strtolower(substr($this->_query, 0, 6)) == 'select' && $this->_results != null) | ||
| 75 | if (strtolower(substr($this->_query, 0, 6)) == 'select' && | ||
| 76 | $this->_results != null) | ||
| 76 | 77 | return sqlite_num_rows($this->_results); | |
| 77 | 78 | else if ($this->_results === true) | |
| 78 | 79 | return $this->affectedRows(); | |
| … | … | ||
| 82 | 82 | ||
| 83 | 83 | public function affectedRows () | |
| 84 | 84 | { | |
| 85 | if (in_array(strtolower(substr($this->_query, 0, 7)), array('insert ', 'update ', 'replace', 'delete '))) | ||
| 85 | if (in_array(strtolower(substr($this->_query, 0, 7)), | ||
| 86 | array('insert ', 'update ', 'replace', 'delete '))) | ||
| 86 | 87 | return sqlite_changes($this->_connection); | |
| 87 | 88 | else return null; | |
| 88 | } | ||
| 89 | |||
| 90 | public function freeResults () | ||
| 91 | { | ||
| 92 | if (substr($this->_query, 0, 6) == 'SELECT' && $this->_results != null) | ||
| 93 | mysql_free_result($this->_results); | ||
| 94 | 89 | } | |
| 95 | 90 | ||
| 96 | 91 | } |

