Rev 48 | Rev 52 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 48 | Rev 51 | ||
|---|---|---|---|
| Line 1... | Line 1... | ||
| 1 | <?php
|
1 | <?php
|
| 2 | 2 | ||
| - | 3 | namespace PointedEars\PHPX\Db; |
|
| - | 4 | ||
| 3 | require_once __DIR__ . '/../global.inc'; |
5 | require_once __DIR__ . '/../global.inc'; |
| 4 | require_once __DIR__ . '/../AbstractModel.php'; |
6 | require_once __DIR__ . '/../AbstractModel.php'; |
| 5 | 7 | ||
| 6 | /**
|
8 | /**
|
| 7 | * Generic database model class using PDO (PHP Data Objects)
|
9 | * Generic database model class using PDO (PHP Data Objects)
|
| Line 19... | Line 21... | ||
| 19 | * Last result of the database operation
|
21 | * Last result of the database operation
|
| 20 | * @property-read boolean $lastSuccess
|
22 | * @property-read boolean $lastSuccess
|
| 21 | * Last success value of the database operation
|
23 | * Last success value of the database operation
|
| 22 | * @author Thomas Lahn
|
24 | * @author Thomas Lahn
|
| 23 | */
|
25 | */
|
| 24 | class Database extends AbstractModel |
26 | class Database extends \PointedEars\PHPX\AbstractModel |
| 25 | {
|
27 | {
|
| 26 | /* Access properties */
|
28 | /* Access properties */
|
| 27 | 29 | ||
| 28 | /**
|
30 | /**
|
| 29 | * DSN of the database
|
31 | * DSN of the database
|
| Line 187... | Line 189... | ||
| 187 | public function getConnection () |
189 | public function getConnection () |
| 188 | {
|
190 | {
|
| 189 | if ($this->_connection === null) |
191 | if ($this->_connection === null) |
| 190 | {
|
192 | {
|
| 191 | $this->_connection = |
193 | $this->_connection = |
| 192 | new PDO($this->_dsn, $this->_username, $this->_password, $this->_options); |
194 | new \PDO($this->_dsn, $this->_username, $this->_password, $this->_options); |
| 193 | }
|
195 | }
|
| 194 | 196 | ||
| 195 | return $this->_connection; |
197 | return $this->_connection; |
| 196 | }
|
198 | }
|
| 197 | 199 | ||
| Line 477... | Line 479... | ||
| 477 | * @return array
|
479 | * @return array
|
| 478 | * @see Database::prepare()
|
480 | * @see Database::prepare()
|
| 479 | * @see PDOStatement::fetchAll()
|
481 | * @see PDOStatement::fetchAll()
|
| 480 | */
|
482 | */
|
| 481 | public function select($tables, $columns = null, $where = null, |
483 | public function select($tables, $columns = null, $where = null, |
| 482 | $order = null, $limit = null, $fetch_style = PDO::FETCH_ASSOC) |
484 | $order = null, $limit = null, $fetch_style = \PDO::FETCH_ASSOC) |
| 483 | {
|
485 | {
|
| 484 | if (is_null($columns)) |
486 | if (is_null($columns)) |
| 485 | {
|
487 | {
|
| 486 | $columns = array('*'); |
488 | $columns = array('*'); |
| 487 | }
|
489 | }
|
| Line 837... | Line 839... | ||
| 837 | 839 | ||
| 838 | $result =& $this->_lastResult; |
840 | $result =& $this->_lastResult; |
| 839 | 841 | ||
| 840 | if (is_null($fetch_style)) |
842 | if (is_null($fetch_style)) |
| 841 | {
|
843 | {
|
| 842 | $fetch_style = PDO::FETCH_ASSOC; |
844 | $fetch_style = \PDO::FETCH_ASSOC; |
| 843 | }
|
845 | }
|
| 844 | 846 | ||
| 845 | if (!is_null($ctor_args)) |
847 | if (!is_null($ctor_args)) |
| 846 | {
|
848 | {
|
| 847 | $result = $stmt->fetchAll($fetch_style, $column_index, $ctor_args); |
849 | $result = $stmt->fetchAll($fetch_style, $column_index, $ctor_args); |