hpdl
|
1122
|
1
|
<?php
|
|
2
|
/*
|
|
3
|
$Id: $
|
|
4
|
|
|
5
|
osCommerce, Open Source E-Commerce Solutions
|
|
6
|
http://www.oscommerce.com
|
|
7
|
|
hpdl
|
1372
|
8
|
Copyright (c) 2007 osCommerce
|
hpdl
|
1122
|
9
|
|
hpdl
|
1498
|
10
|
This program is free software; you can redistribute it and/or modify
|
|
11
|
it under the terms of the GNU General Public License v2 (1991)
|
|
12
|
as published by the Free Software Foundation.
|
hpdl
|
1122
|
13
|
*/
|
|
14
|
|
|
15
|
require('mysql.php');
|
|
16
|
|
|
17
|
class osC_Database_mysqli extends osC_Database_mysql {
|
hpdl
|
1123
|
18
|
var $use_transactions = true;
|
hpdl
|
1122
|
19
|
|
|
20
|
function osC_Database_mysqli($server, $username, $password) {
|
|
21
|
$this->server = $server;
|
|
22
|
$this->username = $username;
|
|
23
|
$this->password = $password;
|
|
24
|
|
|
25
|
if ($this->is_connected === false) {
|
|
26
|
$this->connect();
|
|
27
|
}
|
|
28
|
}
|
|
29
|
|
|
30
|
function connect() {
|
|
31
|
if ($this->link = @mysqli_connect($this->server, $this->username, $this->password)) {
|
|
32
|
$this->setConnected(true);
|
|
33
|
|
hpdl
|
1865
|
34
|
if ( version_compare(mysqli_get_server_info($this->link), '5.0.2') >= 0 ) {
|
|
35
|
$this->simpleQuery('set session sql_mode="STRICT_ALL_TABLES"');
|
|
36
|
}
|
|
37
|
|
hpdl
|
1122
|
38
|
return true;
|
|
39
|
} else {
|
|
40
|
$this->setError(mysqli_connect_error(), mysqli_connect_errno());
|
|
41
|
|
|
42
|
return false;
|
|
43
|
}
|
|
44
|
}
|
|
45
|
|
|
46
|
function disconnect() {
|
|
47
|
if ($this->isConnected()) {
|
|
48
|
if (@mysqli_close($this->link)) {
|
|
49
|
return true;
|
|
50
|
} else {
|
|
51
|
return false;
|
|
52
|
}
|
|
53
|
} else {
|
|
54
|
return true;
|
|
55
|
}
|
|
56
|
}
|
|
57
|
|
|
58
|
function selectDatabase($database) {
|
|
59
|
if ($this->isConnected()) {
|
|
60
|
if (@mysqli_select_db($this->link, $database)) {
|
|
61
|
return true;
|
|
62
|
} else {
|
|
63
|
$this->setError(mysqli_error($this->link), mysqli_errno($this->link));
|
|
64
|
|
|
65
|
return false;
|
|
66
|
}
|
|
67
|
} else {
|
|
68
|
return false;
|
|
69
|
}
|
|
70
|
}
|
|
71
|
|
|
72
|
function parseString($value) {
|
|
73
|
return mysqli_real_escape_string($this->link, $value);
|
|
74
|
}
|
|
75
|
|
|
76
|
function simpleQuery($query, $debug = false) {
|
hpdl
|
1863
|
77
|
global $osC_MessageStack, $osC_Services;
|
hpdl
|
1122
|
78
|
|
|
79
|
if ($this->isConnected()) {
|
|
80
|
$this->number_of_queries++;
|
|
81
|
|
|
82
|
if ( ($debug === false) && ($this->debug === true) ) {
|
|
83
|
$debug = true;
|
|
84
|
}
|
|
85
|
|
|
86
|
if (isset($osC_Services) && $osC_Services->isStarted('debug')) {
|
|
87
|
if ( ($debug === false) && (SERVICE_DEBUG_OUTPUT_DB_QUERIES == '1') ) {
|
|
88
|
$debug = true;
|
|
89
|
}
|
|
90
|
|
|
91
|
if (!osc_empty(SERVICE_DEBUG_EXECUTION_TIME_LOG) && (SERVICE_DEBUG_LOG_DB_QUERIES == '1')) {
|
|
92
|
@error_log('QUERY ' . $query . "\n", 3, SERVICE_DEBUG_EXECUTION_TIME_LOG);
|
|
93
|
}
|
|
94
|
} elseif ($debug === true) {
|
|
95
|
$debug = false;
|
|
96
|
}
|
|
97
|
|
|
98
|
if ($debug === true) {
|
|
99
|
$time_start = $this->getMicroTime();
|
|
100
|
}
|
|
101
|
|
|
102
|
$resource = @mysqli_query($this->link, $query);
|
|
103
|
|
|
104
|
if ($debug === true) {
|
|
105
|
$time_end = $this->getMicroTime();
|
|
106
|
|
|
107
|
$query_time = number_format($time_end - $time_start, 5);
|
|
108
|
|
|
109
|
if ($this->debug === true) {
|
|
110
|
$this->time_of_queries += $query_time;
|
|
111
|
}
|
|
112
|
|
|
113
|
echo '<div style="font-family: Verdana, Arial, sans-serif; font-size: 7px; font-weight: bold;">[<a href="#query' . $this->number_of_queries . '">#' . $this->number_of_queries . '</a>]</div>';
|
|
114
|
|
hpdl
|
1863
|
115
|
$osC_MessageStack->add('debug', '<a name=\'query' . $this->number_of_queries . '\'></a>[#' . $this->number_of_queries . ' - ' . $query_time . 's] ' . $query, 'warning');
|
hpdl
|
1122
|
116
|
}
|
|
117
|
|
|
118
|
if ($resource !== false) {
|
|
119
|
$this->error = false;
|
|
120
|
$this->error_number = null;
|
|
121
|
$this->error_query = null;
|
|
122
|
|
hpdl
|
1865
|
123
|
if ( mysqli_warning_count($this->link) > 0 ) {
|
|
124
|
$warning_query = @mysqli_query($this->link, 'show warnings');
|
|
125
|
while ( $warning = mysqli_fetch_row($warning_query) ) {
|
|
126
|
trigger_error(sprintf('[MYSQL] %s (%d): %s [QUERY] ' . $query, $warning[0], $warning[1], $warning[2]), E_USER_WARNING);
|
|
127
|
}
|
|
128
|
mysqli_free_result($warning_query);
|
|
129
|
}
|
|
130
|
|
hpdl
|
1122
|
131
|
return $resource;
|
|
132
|
} else {
|
|
133
|
$this->setError(mysqli_error($this->link), mysqli_errno($this->link), $query);
|
|
134
|
|
|
135
|
return false;
|
|
136
|
}
|
|
137
|
} else {
|
|
138
|
return false;
|
|
139
|
}
|
|
140
|
}
|
|
141
|
|
|
142
|
function dataSeek($row_number, $resource) {
|
|
143
|
return @mysqli_data_seek($resource, $row_number);
|
|
144
|
}
|
|
145
|
|
|
146
|
function next($resource) {
|
|
147
|
return @mysqli_fetch_assoc($resource);
|
|
148
|
}
|
|
149
|
|
|
150
|
function freeResult($resource) {
|
|
151
|
return @mysqli_free_result($resource);
|
|
152
|
}
|
|
153
|
|
|
154
|
function nextID() {
|
hpdl
|
1372
|
155
|
if ( is_numeric($this->nextID) ) {
|
|
156
|
$id = $this->nextID;
|
|
157
|
$this->nextID = null;
|
|
158
|
|
hpdl
|
1122
|
159
|
return $id;
|
hpdl
|
1372
|
160
|
} elseif ($id = @mysqli_insert_id($this->link)) {
|
|
161
|
return $id;
|
hpdl
|
1122
|
162
|
} else {
|
|
163
|
$this->setError(mysqli_error($this->link), mysqli_errno($this->link));
|
|
164
|
|
|
165
|
return false;
|
|
166
|
}
|
|
167
|
}
|
|
168
|
|
|
169
|
function numberOfRows($resource) {
|
|
170
|
return @mysqli_num_rows($resource);
|
|
171
|
}
|
|
172
|
|
|
173
|
function affectedRows() {
|
|
174
|
return @mysqli_affected_rows($this->link);
|
|
175
|
}
|
|
176
|
|
|
177
|
function startTransaction() {
|
hpdl
|
1372
|
178
|
$this->logging_transaction = true;
|
|
179
|
|
hpdl
|
1122
|
180
|
if ($this->use_transactions === true) {
|
|
181
|
return @mysqli_autocommit($this->link, false);
|
|
182
|
}
|
|
183
|
|
|
184
|
return false;
|
|
185
|
}
|
|
186
|
|
|
187
|
function commitTransaction() {
|
hpdl
|
1372
|
188
|
if ($this->logging_transaction === true) {
|
|
189
|
$this->logging_transaction = false;
|
|
190
|
$this->logging_transaction_action = false;
|
|
191
|
}
|
|
192
|
|
hpdl
|
1122
|
193
|
if ($this->use_transactions === true) {
|
|
194
|
$result = @mysqli_commit($this->link);
|
|
195
|
|
|
196
|
@mysqli_autocommit($this->link, true);
|
|
197
|
|
|
198
|
return $result;
|
|
199
|
}
|
|
200
|
|
|
201
|
return false;
|
|
202
|
}
|
|
203
|
|
|
204
|
function rollbackTransaction() {
|
hpdl
|
1372
|
205
|
if ($this->logging_transaction === true) {
|
|
206
|
$this->logging_transaction = false;
|
|
207
|
$this->logging_transaction_action = false;
|
|
208
|
}
|
|
209
|
|
hpdl
|
1122
|
210
|
if ($this->use_transactions === true) {
|
|
211
|
$result = @mysqli_rollback($this->link);
|
|
212
|
|
|
213
|
@mysqli_autocommit($this->link, true);
|
|
214
|
|
|
215
|
return $result;
|
|
216
|
}
|
|
217
|
|
|
218
|
return false;
|
|
219
|
}
|
|
220
|
}
|
|
221
|
?>
|