3 * SO2 custom PDO class. Way better than the so2mysqli one.
5 * @author Ant P <p@cpi.merseine.nu>
6 * @license file://../COPYING
9 class SO2_PDO
extends PDO
11 const QSMART
= PDO
::FETCH_LAZY
;
12 const QVALUE
= PDO
::FETCH_COLUMN
;
13 const QROW
= PDO
::FETCH_NUM
;
14 const QASSOC
= PDO
::FETCH_ASSOC
;
15 const QOBJ
= PDO
::FETCH_OBJ
;
19 * This is made of amazing.
20 * @param $q string SQL query
21 * @param $params mixed Array or single parameter for prepared statement placeholders
22 * @param $fetch int Determines the return type. Default is auto-detection
25 public function q($q, $params = null, $fetch = self
::QSMART
)
27 //echo '<!--'.$q.print_r($params,1).print_r(debug_backtrace(), 1)."-->\n\n";
29 if ( self
::QSMART
== $fetch ) {
30 if ( strpos($q, 'SELECT') === 0 ) { // Default for selects is to return assoc array
31 $fetch = self
::QASSOC
;
32 } else { // Anything else is null
37 $tmp = $this->prepare($q);
38 $tmp->execute((array)$params);
40 case self
::QVALUE
: // Return first column
41 return $tmp->fetchColumn(0);
42 case self
::QROW
: // Return numeric array
43 return $tmp->fetch(PDO
::FETCH_NUM
);
44 case self
::QASSOC
: // Return assoc array
45 return $tmp->fetch(PDO
::FETCH_ASSOC
);
46 case self
::QOBJ
: // Return the result directly; can then be used with PDO's fetch*()
48 case self
::QNONE
: // Return nothing
51 trigger_error('Unknown return type requested in SO2_PDO::q(): '.$fetch, E_USER_WARNING
);