Quick Search:

View

Revision:

Diff

Diff from 1321 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/osCommerce/trunk/oscommerce/includes/classes/database/mysqli.php

Annotated File View

hpdl
1122
1 <?php
2 /*
3   $Id: $
4
5   osCommerce, Open Source E-Commerce Solutions
6   http://www.oscommerce.com
7
8   Copyright (c) 2006 osCommerce
9
10   Released under the GNU General Public License
11 */
12
13   require('mysql.php');
14
15   class osC_Database_mysqli extends osC_Database_mysql {
hpdl
1123
16     var $use_transactions = true;
hpdl
1122
17
18     function osC_Database_mysqli($server, $username, $password) {
19       $this->server = $server;
20       $this->username = $username;
21       $this->password = $password;
22
23       if ($this->is_connected === false) {
24         $this->connect();
25       }
26     }
27
28     function connect() {
29       if ($this->link = @mysqli_connect($this->server, $this->username, $this->password)) {
30         $this->setConnected(true);
31
32         return true;
33       } else {
34         $this->setError(mysqli_connect_error(), mysqli_connect_errno());
35
36         return false;
37       }
38     }
39
40     function disconnect() {
41       if ($this->isConnected()) {
42         if (@mysqli_close($this->link)) {
43           return true;
44         } else {
45           return false;
46         }
47       } else {
48         return true;
49       }
50     }
51
52     function selectDatabase($database) {
53       if ($this->isConnected()) {
54         if (@mysqli_select_db($this->link, $database)) {
55           return true;
56         } else {
57           $this->setError(mysqli_error($this->link), mysqli_errno($this->link));
58
59           return false;
60         }
61       } else {
62         return false;
63       }
64     }
65
66     function parseString($value) {
67       return mysqli_real_escape_string($this->link, $value);
68     }
69
70     function simpleQuery($query, $debug = false) {
71       global $messageStack, $osC_Services;
72
73       if ($this->isConnected()) {
74         $this->number_of_queries++;
75
76         if ( ($debug === false) && ($this->debug === true) ) {
77           $debug = true;
78         }
79
80         if (isset($osC_Services) && $osC_Services->isStarted('debug')) {
81           if ( ($debug === false) && (SERVICE_DEBUG_OUTPUT_DB_QUERIES == '1') ) {
82             $debug = true;
83           }
84
85           if (!osc_empty(SERVICE_DEBUG_EXECUTION_TIME_LOG) && (SERVICE_DEBUG_LOG_DB_QUERIES == '1')) {
86             @error_log('QUERY ' . $query . "\n", 3, SERVICE_DEBUG_EXECUTION_TIME_LOG);
87           }
88         } elseif ($debug === true) {
89           $debug = false;
90         }
91
92         if ($debug === true) {
93           $time_start = $this->getMicroTime();
94         }
95
96         $resource = @mysqli_query($this->link, $query);
97
98         if ($debug === true) {
99           $time_end = $this->getMicroTime();
100
101           $query_time = number_format($time_end - $time_start, 5);
102
103           if ($this->debug === true) {
104             $this->time_of_queries += $query_time;
105           }
106
107           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>';
108
109           $messageStack->add('debug', '<a name=\'query' . $this->number_of_queries . '\'></a>[#' . $this->number_of_queries . ' - ' . $query_time . 's] ' . $query, 'warning');
110         }
111
112         if ($resource !== false) {
113           $this->error = false;
114           $this->error_number = null;
115           $this->error_query = null;
116
117           return $resource;
118         } else {
119           $this->setError(mysqli_error($this->link), mysqli_errno($this->link), $query);
120
121           return false;
122         }
123       } else {
124         return false;
125       }
126     }
127
128     function dataSeek($row_number, $resource) {
129       return @mysqli_data_seek($resource, $row_number);
130     }
131
132     function next($resource) {
133       return @mysqli_fetch_assoc($resource);
134     }
135
136     function freeResult($resource) {
137       return @mysqli_free_result($resource);
138     }
139
140     function nextID() {
141       if ($id = @mysqli_insert_id($this->link)) {
142         return $id;
143       } else {
144         $this->setError(mysqli_error($this->link), mysqli_errno($this->link));
145
146         return false;
147       }
148     }
149
150     function numberOfRows($resource) {
151       return @mysqli_num_rows($resource);
152     }
153
154     function affectedRows() {
155       return @mysqli_affected_rows($this->link);
156     }
157
158     function startTransaction() {
159       if ($this->use_transactions === true) {
160         return @mysqli_autocommit($this->link, false);
161       }
162
163       return false;
164     }
165
166     function commitTransaction() {
167       if ($this->use_transactions === true) {
168         $result = @mysqli_commit($this->link);
169
170         @mysqli_autocommit($this->link, true);
171
172         return $result;
173       }
174
175       return false;
176     }
177
178     function rollbackTransaction() {
179       if ($this->use_transactions === true) {
180         $result = @mysqli_rollback($this->link);
181
182         @mysqli_autocommit($this->link, true);
183
184         return $result;
185       }
186
187       return false;
188     }
189   }
190 ?>