Quick Search:

View

Revision:

Diff

Diff from 1122 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 {
16     var $sql_parse_string = 'mysqli_real_escape_string',
17         $sql_parse_string_with_connection_handler = true,
18         $use_transactions = true;
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
34         return true;
35       } else {
36         $this->setError(mysqli_connect_error(), mysqli_connect_errno());
37
38         return false;
39       }
40     }
41
42     function disconnect() {
43       if ($this->isConnected()) {
44         if (@mysqli_close($this->link)) {
45           return true;
46         } else {
47           return false;
48         }
49       } else {
50         return true;
51       }
52     }
53
54     function selectDatabase($database) {
55       if ($this->isConnected()) {
56         if (@mysqli_select_db($this->link, $database)) {
57           return true;
58         } else {
59           $this->setError(mysqli_error($this->link), mysqli_errno($this->link));
60
61           return false;
62         }
63       } else {
64         return false;
65       }
66     }
67
68     function parseString($value) {
69       return mysqli_real_escape_string($this->link, $value);
70     }
71
72     function simpleQuery($query, $debug = false) {
73       global $messageStack, $osC_Services;
74
75       if ($this->isConnected()) {
76         $this->number_of_queries++;
77
78         if ( ($debug === false) && ($this->debug === true) ) {
79           $debug = true;
80         }
81
82         if (isset($osC_Services) && $osC_Services->isStarted('debug')) {
83           if ( ($debug === false) && (SERVICE_DEBUG_OUTPUT_DB_QUERIES == '1') ) {
84             $debug = true;
85           }
86
87           if (!osc_empty(SERVICE_DEBUG_EXECUTION_TIME_LOG) && (SERVICE_DEBUG_LOG_DB_QUERIES == '1')) {
88             @error_log('QUERY ' . $query . "\n", 3, SERVICE_DEBUG_EXECUTION_TIME_LOG);
89           }
90         } elseif ($debug === true) {
91           $debug = false;
92         }
93
94         if ($debug === true) {
95           $time_start = $this->getMicroTime();
96         }
97
98         $resource = @mysqli_query($this->link, $query);
99
100         if ($debug === true) {
101           $time_end = $this->getMicroTime();
102
103           $query_time = number_format($time_end - $time_start, 5);
104
105           if ($this->debug === true) {
106             $this->time_of_queries += $query_time;
107           }
108
109           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>';
110
111           $messageStack->add('debug', '<a name=\'query' . $this->number_of_queries . '\'></a>[#' . $this->number_of_queries . ' - ' . $query_time . 's] ' . $query, 'warning');
112         }
113
114         if ($resource !== false) {
115           $this->error = false;
116           $this->error_number = null;
117           $this->error_query = null;
118
119           return $resource;
120         } else {
121           $this->setError(mysqli_error($this->link), mysqli_errno($this->link), $query);
122
123           return false;
124         }
125       } else {
126         return false;
127       }
128     }
129
130     function dataSeek($row_number, $resource) {
131       return @mysqli_data_seek($resource, $row_number);
132     }
133
134     function next($resource) {
135       return @mysqli_fetch_assoc($resource);
136     }
137
138     function freeResult($resource) {
139       return @mysqli_free_result($resource);
140     }
141
142     function nextID() {
143       if ($id = @mysqli_insert_id($this->link)) {
144         return $id;
145       } else {
146         $this->setError(mysqli_error($this->link), mysqli_errno($this->link));
147
148         return false;
149       }
150     }
151
152     function numberOfRows($resource) {
153       return @mysqli_num_rows($resource);
154     }
155
156     function affectedRows() {
157       return @mysqli_affected_rows($this->link);
158     }
159
160     function startTransaction() {
161       if ($this->use_transactions === true) {
162         return @mysqli_autocommit($this->link, false);
163       }
164
165       return false;
166     }
167
168     function commitTransaction() {
169       if ($this->use_transactions === true) {
170         $result = @mysqli_commit($this->link);
171
172         @mysqli_autocommit($this->link, true);
173
174         return $result;
175       }
176
177       return false;
178     }
179
180     function rollbackTransaction() {
181       if ($this->use_transactions === true) {
182         $result = @mysqli_rollback($this->link);
183
184         @mysqli_autocommit($this->link, true);
185
186         return $result;
187       }
188
189       return false;
190     }
191   }
192 ?>