| @@ 137-165 (lines=29) @@ | ||
| 134 | * @param string $className Class name if we want to create object |
|
| 135 | * @return array Collection of arrays or objects |
|
| 136 | */ |
|
| 137 | public function &fetch($sql, $className = null) |
|
| 138 | { |
|
| 139 | // Return value |
|
| 140 | $result = array(); |
|
| 141 | ||
| 142 | if (isset($this->driver)) { |
|
| 143 | // Store timestamp |
|
| 144 | $tsLast = microtime(true); |
|
| 145 | ||
| 146 | try { |
|
| 147 | // Perform database query |
|
| 148 | if (!isset($className)) { // Return array |
|
| 149 | $result = $this->driver->query($sql)->fetchAll(\PDO::FETCH_ASSOC); |
|
| 150 | } else { // Create object of passed class name |
|
| 151 | $result = $this->driver->query($sql)->fetchAll(\PDO::FETCH_CLASS, $className, array(&$this)); |
|
| 152 | } |
|
| 153 | } catch (\PDOException $e) { |
|
| 154 | echo("\n" . $sql . '-' . $e->getMessage()); |
|
| 155 | } |
|
| 156 | ||
| 157 | // Store queries count |
|
| 158 | $this->count++; |
|
| 159 | ||
| 160 | // Count elapsed time |
|
| 161 | $this->elapsed += microtime(true) - $tsLast; |
|
| 162 | } |
|
| 163 | ||
| 164 | return $result; |
|
| 165 | } |
|
| 166 | ||
| 167 | /** |
|
| 168 | * Special accelerated function to retrieve db record fields instead of objects |
|
| @@ 217-246 (lines=30) @@ | ||
| 214 | * @param string $className Class name if we want to create object |
|
| 215 | * @return array|object Record as array or object |
|
| 216 | */ |
|
| 217 | public function &fetchOne($sql, $className = null) |
|
| 218 | { |
|
| 219 | // Return value, configure to return correct type |
|
| 220 | $result = isset($className) ? new \stdClass() : array(); |
|
| 221 | ||
| 222 | if (isset($this->driver)) { |
|
| 223 | // Store timestamp |
|
| 224 | $tsLast = microtime(true); |
|
| 225 | ||
| 226 | try { |
|
| 227 | // Perform database query |
|
| 228 | if (!isset($className)) { // Return array |
|
| 229 | $result = $this->driver->query($sql)->fetch(\PDO::FETCH_ASSOC); |
|
| 230 | } else { // Create object of passed class name |
|
| 231 | $result = $this->driver->query($sql)->fetchObject($className, array(&$this)); |
|
| 232 | } |
|
| 233 | ||
| 234 | } catch (\PDOException $e) { |
|
| 235 | echo("\n" . $sql . '-' . $e->getMessage()); |
|
| 236 | } |
|
| 237 | ||
| 238 | // Store queries count |
|
| 239 | $this->count++; |
|
| 240 | ||
| 241 | // Count elapsed time |
|
| 242 | $this->elapsed += microtime(true) - $tsLast; |
|
| 243 | } |
|
| 244 | ||
| 245 | return $result; |
|
| 246 | } |
|
| 247 | ||
| 248 | public function create($className, &$object = null) |
|
| 249 | { |
|