Rev 34 | Rev 44 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 34 | Rev 41 | ||
---|---|---|---|
Line 4... | Line 4... | ||
4 | require_once __DIR__ . '/../AbstractModel.php'; |
4 | require_once __DIR__ . '/../AbstractModel.php'; |
5 | 5 | ||
6 | /**
|
6 | /**
|
7 | * Generic database model class using PDO (PHP Data Objects)
|
7 | * Generic database model class using PDO (PHP Data Objects)
|
8 | *
|
8 | *
|
- | 9 | * @property-read PDO $connection
|
|
- | 10 | * Database connection. Established on read access to this
|
|
- | 11 | * property if not yet established.
|
|
9 | * @property-read array $lastError
|
12 | * @property-read array $lastError
|
10 | * Last error information of the database operation.
|
13 | * Last error information of the database operation.
|
11 | * See {@link PDOStatement::errorInfo()}.
|
14 | * See {@link PDOStatement::errorInfo()}.
|
12 | * @property-read string $lastInsertId
|
15 | * @property-read string $lastInsertId
|
13 | * ID of the last inserted row, or the last value from a sequence object,
|
16 | * ID of the last inserted row, or the last value from a sequence object,
|
Line 130... | Line 133... | ||
130 | 133 | ||
131 | if ($options) |
134 | if ($options) |
132 | {
|
135 | {
|
133 | $this->_options = $options; |
136 | $this->_options = $options; |
134 | }
|
137 | }
|
- | 138 | }
|
|
135 | 139 | ||
- | 140 | /**
|
|
- | 141 | * @return PDO
|
|
- | 142 | */
|
|
- | 143 | public function getConnection () |
|
- | 144 | {
|
|
- | 145 | if ($this->_connection === null) |
|
- | 146 | {
|
|
136 | $this->_connection = |
147 | $this->_connection = |
137 | new PDO($this->_dsn, $this->_username, $this->_password, $this->_options); |
148 | new PDO($this->_dsn, $this->_username, $this->_password, $this->_options); |
138 | }
|
149 | }
|
139 | 150 | ||
- | 151 | return $this->_connection; |
|
- | 152 | }
|
|
- | 153 | ||
140 | /**
|
154 | /**
|
141 | * Initiates a transaction
|
155 | * Initiates a transaction
|
142 | *
|
156 | *
|
143 | * @return bool
|
157 | * @return bool
|
144 | * @see PDO::beginTransaction()
|
158 | * @see PDO::beginTransaction()
|
145 | */
|
159 | */
|
146 | public function beginTransaction() |
160 | public function beginTransaction() |
147 | {
|
161 | {
|
148 | return $this->_connection->beginTransaction(); |
162 | return $this->connection->beginTransaction(); |
149 | }
|
163 | }
|
150 | 164 | ||
151 | /**
|
165 | /**
|
152 | * Rolls back a transaction
|
166 | * Rolls back a transaction
|
153 | *
|
167 | *
|
154 | * @return bool
|
168 | * @return bool
|
155 | * @see PDO::rollBack()
|
169 | * @see PDO::rollBack()
|
156 | */
|
170 | */
|
157 | public function rollBack() |
171 | public function rollBack() |
158 | {
|
172 | {
|
159 | return $this->_connection->rollBack(); |
173 | return $this->connection->rollBack(); |
160 | }
|
174 | }
|
161 | 175 | ||
162 | /**
|
176 | /**
|
163 | * Commits a transaction
|
177 | * Commits a transaction
|
164 | *
|
178 | *
|
165 | * @return bool
|
179 | * @return bool
|
166 | * @see PDO::commit()
|
180 | * @see PDO::commit()
|
167 | */
|
181 | */
|
168 | public function commit() |
182 | public function commit() |
169 | {
|
183 | {
|
170 | return $this->_connection->commit(); |
184 | return $this->connection->commit(); |
171 | }
|
185 | }
|
172 | 186 | ||
173 | /**
|
187 | /**
|
174 | * Prepares a statement for execution with the database
|
188 | * Prepares a statement for execution with the database
|
175 | * @param string $query
|
189 | * @param string $query
|
176 | */
|
190 | */
|
177 | public function prepare($query, array $driver_options = array()) |
191 | public function prepare($query, array $driver_options = array()) |
178 | {
|
192 | {
|
179 | return $this->_connection->prepare($query, $driver_options); |
193 | return $this->connection->prepare($query, $driver_options); |
180 | }
|
194 | }
|
181 | 195 | ||
182 | /**
|
196 | /**
|
183 | * Returns the ID of the last inserted row, or the last value from
|
197 | * Returns the ID of the last inserted row, or the last value from
|
184 | * a sequence object, depending on the underlying driver.
|
198 | * a sequence object, depending on the underlying driver.
|
Line 486... | Line 500... | ||
486 | * Name of the sequence object from which the ID should be returned.
|
500 | * Name of the sequence object from which the ID should be returned.
|
487 | * @return string
|
501 | * @return string
|
488 | */
|
502 | */
|
489 | protected function _setLastInsertId($name = null) |
503 | protected function _setLastInsertId($name = null) |
490 | {
|
504 | {
|
491 | return ($this->_lastInsertId = $this->_connection->lastInsertId($name)); |
505 | return ($this->_lastInsertId = $this->connection->lastInsertId($name)); |
492 | }
|
506 | }
|
493 | 507 | ||
494 | /**
|
508 | /**
|
495 | * Resets the the ID of the last inserted row, or the last value from
|
509 | * Resets the the ID of the last inserted row, or the last value from
|
496 | * a sequence object, depending on the underlying driver.
|
510 | * a sequence object, depending on the underlying driver.
|