@@ 102-125 (lines=24) @@ | ||
99 | * @param string $sql SQL statement |
|
100 | * @return mixed Database query result |
|
101 | */ |
|
102 | public function &query($sql) |
|
103 | { |
|
104 | $result = array(); |
|
105 | ||
106 | if (isset($this->driver)) { |
|
107 | // Store timestamp |
|
108 | $tsLast = microtime(true); |
|
109 | ||
110 | try { |
|
111 | // Perform database query |
|
112 | $result = $this->driver->prepare($sql)->execute(); |
|
113 | } catch (\PDOException $e) { |
|
114 | echo("\n" . $sql . '-' . $e->getMessage()); |
|
115 | } |
|
116 | ||
117 | // Store queries count |
|
118 | $this->count++; |
|
119 | ||
120 | // Count elapsed time |
|
121 | $this->elapsed += microtime(true) - $tsLast; |
|
122 | } |
|
123 | ||
124 | return $result; |
|
125 | } |
|
126 | ||
127 | /** |
|
128 | * Retrieve array of records from a database, if $className is passed method |
@@ 42-65 (lines=24) @@ | ||
39 | $this->driver = $driver; |
|
40 | } |
|
41 | ||
42 | public function execute($sql) |
|
43 | { |
|
44 | $result = array(); |
|
45 | ||
46 | if (isset($this->driver)) { |
|
47 | // Store timestamp |
|
48 | $tsLast = microtime(true); |
|
49 | ||
50 | try { |
|
51 | // Perform database query |
|
52 | $result = $this->driver->prepare($sql)->execute(); |
|
53 | } catch (\PDOException $e) { |
|
54 | echo("\n" . $sql . '-' . $e->getMessage()); |
|
55 | } |
|
56 | ||
57 | // Store queries count |
|
58 | $this->count++; |
|
59 | ||
60 | // Count elapsed time |
|
61 | $this->elapsed += microtime(true) - $tsLast; |
|
62 | } |
|
63 | ||
64 | return $result; |
|
65 | } |
|
66 | ||
67 | /** |
|
68 | * Get query for database entity to work with. |