1: <?php
2: 3: 4: 5: 6: 7:
8: abstract class QPdoDatabase extends QDatabaseBase {
9: const Adapter = 'Generic PDO Adapter (Abstract)';
10:
11: 12: 13: 14:
15: protected $objPdo;
16: 17: 18: 19:
20: protected $objMostRecentResult;
21:
22:
23: protected function ExecuteNonQuery($strNonQuery) {
24:
25: $objResult = $this->objPdo->query($strNonQuery);
26: if ($objResult === false)
27: throw new QPdoDatabaseException($this->objPdo->errorInfo(), $this->objPdo->errorCode(), $strNonQuery);
28: $this->objMostRecentResult = $objResult;
29: }
30:
31: public function __get($strName) {
32: switch ($strName) {
33: case 'AffectedRows':
34: return $this->objMostRecentResult->rowCount();
35: default:
36: try {
37: return parent::__get($strName);
38: } catch (QCallerException $objExc) {
39: $objExc->IncrementOffset();
40: throw $objExc;
41: }
42: }
43: }
44:
45: public function Close() {
46: $this->objPdo = null;
47: }
48:
49:
50: protected function ExecuteTransactionBegin() {
51: if (!$this->blnConnectedFlag) {
52: $this->Connect();
53: }
54: $this->objPdo->beginTransaction();
55: }
56:
57: protected function ExecuteTransactionCommit() {
58: $this->objPdo->commit();
59: }
60:
61: protected function ExecuteTransactionRollBack() {
62: $this->objPdo->rollback();
63: }
64:
65: }
66: 67: 68: 69: 70:
71: abstract class QPdoDatabaseResult extends QDatabaseResultBase {
72: 73: 74: 75:
76: protected $objPdoResult;
77: 78: 79: 80:
81: protected $objPdo;
82:
83: public function __construct($objResult, QPdoDatabase $objDb) {
84: $this->objPdoResult = $objResult;
85: $this->objPdo = $objDb;
86: }
87:
88: public function FetchArray() {
89: return $this->objPdoResult->fetch();
90: }
91:
92: public function FetchRow() {
93: return $this->objPdoResult->fetch(PDO::FETCH_NUM);
94: }
95:
96: public function CountRows() {
97: return $this->objPdoResult->rowCount();
98: }
99:
100: public function CountFields() {
101: return $this->objPdoResult->columnCount();
102: }
103:
104: public function Close() {
105: $this->objPdoResult = null;
106: }
107:
108: public function GetRows() {
109: $objDbRowArray = array();
110: while ($objDbRow = $this->GetNextRow())
111: array_push($objDbRowArray, $objDbRow);
112: return $objDbRowArray;
113: }
114: }
115: 116: 117: 118: 119:
120: class QPdoDatabaseException extends QDatabaseExceptionBase {
121: public function __construct($strMessage, $intNumber, $strQuery) {
122: parent::__construct(sprintf("PDO %s", $strMessage[2]), 2);
123: $this->intErrorNumber = $intNumber;
124: $this->strQuery = $strQuery;
125: }
126: }