move content fetcher class
[stapibas.git] / src / stapibas / PDO.php
1 <?php
2 namespace stapibas;
3
4 /**
5  * Small error-handling wrapper around PDO
6  */
7 class PDO extends \PDO
8 {
9     public function query()
10     {
11         $args = func_get_args();
12         $res = call_user_func_array(array('parent', 'query'), $args);
13         if ($res !== false) {
14             return $res;
15         }
16
17         $this->handleError();
18     }
19
20     public function exec($statement)
21     {
22         $res = parent::exec($statement);
23         if ($res !== false) {
24             return $res;
25         }
26
27         $this->handleError();
28     }
29
30     protected function handleError()
31     {
32         echo "SQL error\n";
33         echo " " . $this->errorCode() . "\n";
34         echo " " . implode(' - ', $this->errorInfo()) . "\n";
35         exit(2);
36     }
37 }
38
39 ?>