|
@@ 151-162 (lines=12) @@
|
| 148 |
|
return $res ? $res->fetchColumn($column) : null; |
| 149 |
|
} |
| 150 |
|
|
| 151 |
|
public function each($query, $params=[], callable $looper = null){ |
| 152 |
|
if(!$this->connection()) return false; |
| 153 |
|
|
| 154 |
|
// ($query,$looper) shorthand |
| 155 |
|
if ($looper===null && is_callable($params)) {$looper = $params; $params = [];} |
| 156 |
|
if( $res = $this->exec($query,$params) ){ |
| 157 |
|
if(is_callable($looper)) |
| 158 |
|
while ($row = $res->fetchObject()) $looper($row); |
| 159 |
|
else |
| 160 |
|
return $res->fetchAll(PDO::FETCH_CLASS); |
| 161 |
|
} |
| 162 |
|
} |
| 163 |
|
|
| 164 |
|
public function single($query, $params=[], callable $handler = null){ |
| 165 |
|
if(!$this->connection()) return false; |
|
@@ 164-175 (lines=12) @@
|
| 161 |
|
} |
| 162 |
|
} |
| 163 |
|
|
| 164 |
|
public function single($query, $params=[], callable $handler = null){ |
| 165 |
|
if(!$this->connection()) return false; |
| 166 |
|
|
| 167 |
|
// ($query,$handler) shorthand |
| 168 |
|
if ($handler===null && is_callable($params)) {$handler = $params; $params = [];} |
| 169 |
|
if( $res = $this->exec($query,$params) ){ |
| 170 |
|
if (is_callable($handler)) |
| 171 |
|
$handler($res->fetchObject()); |
| 172 |
|
else |
| 173 |
|
return $res->fetchObject(); |
| 174 |
|
} |
| 175 |
|
} |
| 176 |
|
|
| 177 |
|
public function run($script){ |
| 178 |
|
if(!$this->connection()) return false; |