1: <?php
2:
3: if (!class_exists('QMySqliDatabase'))
4: require(__QCUBED_CORE__ . '/database/QMySqliDatabase.class.php');
5:
6:
7: if (!defined('MYSQLI_TYPE_NEWDECIMAL'))
8: define('MYSQLI_TYPE_NEWDECIMAL', 246);
9: if (!defined('MYSQLI_TYPE_BIT'))
10: define('MYSQLI_TYPE_BIT', 16);
11:
12: 13: 14: 15:
16: class QMySqli5Database extends QMySqliDatabase {
17: const Adapter = 'MySql Improved Database Adapter for MySQL 5';
18:
19: public function GetTables() {
20:
21: if (!$this->blnConnectedFlag) $this->Connect();
22:
23:
24:
25: $strDatabaseName = $this->Database;
26:
27: $objResult = $this->Query("
28: SELECT
29: table_name
30: FROM
31: information_schema.tables
32: WHERE
33: table_type <> 'VIEW' AND
34: table_schema = '$strDatabaseName';
35: ");
36:
37: $strToReturn = array();
38: while ($strRowArray = $objResult->FetchRow())
39: array_push($strToReturn, $strRowArray[0]);
40: return $strToReturn;
41: }
42:
43: protected function ExecuteQuery($strQuery) {
44:
45: $objResult = $this->objMySqli->query($strQuery);
46: if ($this->objMySqli->error)
47: throw new QMySqliDatabaseException($this->objMySqli->error, $this->objMySqli->errno, $strQuery);
48:
49: if (is_bool($objResult)) {
50: throw new QCallerException ("Use ExecuteNonQuery when no results are expected from a query.");
51: }
52:
53:
54: $objMySqliDatabaseResult = new QMySqli5DatabaseResult($objResult, $this);
55: return $objMySqliDatabaseResult;
56: }
57:
58: 59: 60: 61: 62: 63: 64:
65: public function MultiQuery($strQuery) {
66:
67: if (!$this->blnConnectedFlag) $this->Connect();
68:
69:
70: $this->objMySqli->multi_query($strQuery);
71: if ($this->objMySqli->error)
72: throw new QMySqliDatabaseException($this->objMySqli->error, $this->objMySqli->errno, $strQuery);
73:
74: $objResultSets = array();
75: do {
76: if ($objResult = $this->objMySqli->store_result()) {
77: array_push($objResultSets,new QMySqli5DatabaseResult($objResult, $this));
78: }
79: } while ($this->objMySqli->more_results() && $this->objMySqli->next_result());
80:
81: return $objResultSets;
82: }
83:
84: 85: 86: 87: 88: 89: 90: 91: 92:
93: public function ExecuteProcedure($strProcName, $params = null) {
94: $strParams = '';
95: if ($params) {
96: $a = array_map(function ($val) {
97: return $this->SqlVariable($val);
98: }, $params);
99: $strParams = implode(',', $a);
100: }
101: $strSql = "call {$strProcName}({$strParams})";
102: return $this->MultiQuery($strSql);
103: }
104:
105: }
106:
107: 108: 109: 110:
111: class QMySqli5DatabaseResult extends QMySqliDatabaseResult {
112: public function FetchFields() {
113: $objArrayToReturn = array();
114: while ($objField = $this->objMySqliResult->fetch_field())
115: array_push($objArrayToReturn, new QMySqli5DatabaseField($objField, $this->objDb));
116: return $objArrayToReturn;
117: }
118:
119: public function FetchField() {
120: if ($objField = $this->objMySqliResult->fetch_field())
121: return new QMySqli5DatabaseField($objField, $this->objDb);
122: }
123: }
124:
125: 126: 127: 128:
129: class QMySqli5DatabaseField extends QMySqliDatabaseField {
130: protected function SetFieldType($intMySqlFieldType) {
131: switch ($intMySqlFieldType) {
132: case MYSQLI_TYPE_NEWDECIMAL:
133: $this->strType = QDatabaseFieldType::VarChar;
134: break;
135:
136: case MYSQLI_TYPE_BIT:
137: $this->strType = QDatabaseFieldType::Bit;
138: break;
139:
140: default:
141: parent::SetFieldType($intMySqlFieldType);
142: }
143: }
144: }