Quick Search:

View

Revision:

Diff

Diff from 1845 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/osCommerce/branches/hpdl/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
hpdl
1290
8   Copyright (c) 2007 osCommerce
hpdl
1122
9
hpdl
1497
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
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) {
hpdl
1845
73       global $osC_MessageStack, $osC_Services;
hpdl
1122
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
hpdl
1845
111           $osC_MessageStack->add('debug', '<a name=\'query' . $this->number_of_queries . '\'></a>[#' . $this->number_of_queries . ' - ' . $query_time . 's] ' . $query, 'warning');
hpdl
1122
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() {
hpdl
1290
143       if ( is_numeric($this->nextID) ) {
144         $id = $this->nextID;
145         $this->nextID = null;
146
hpdl
1122
147         return $id;
hpdl
1290
148       } elseif ($id = @mysqli_insert_id($this->link)) {
149         return $id;
hpdl
1122
150       } else {
151         $this->setError(mysqli_error($this->link), mysqli_errno($this->link));
152
153         return false;
154       }
155     }
156
157     function numberOfRows($resource) {
158       return @mysqli_num_rows($resource);
159     }
160
161     function affectedRows() {
162       return @mysqli_affected_rows($this->link);
163     }
164
hpdl
1293
165     function startTransaction() {
166       $this->logging_transaction = true;
hpdl
1290
167
hpdl
1122
168       if ($this->use_transactions === true) {
169         return @mysqli_autocommit($this->link, false);
170       }
171
172       return false;
173     }
174
175     function commitTransaction() {
hpdl
1290
176       if ($this->logging_transaction === true) {
177         $this->logging_transaction = false;
178         $this->logging_transaction_action = false;
179       }
180
hpdl
1122
181       if ($this->use_transactions === true) {
182         $result = @mysqli_commit($this->link);
183
184         @mysqli_autocommit($this->link, true);
185
186         return $result;
187       }
188
189       return false;
190     }
191
192     function rollbackTransaction() {
hpdl
1290
193       if ($this->logging_transaction === true) {
194         $this->logging_transaction = false;
195         $this->logging_transaction_action = false;
196       }
197
hpdl
1122
198       if ($this->use_transactions === true) {
199         $result = @mysqli_rollback($this->link);
200
201         @mysqli_autocommit($this->link, true);
202
203         return $result;
204       }
205
206       return false;
207     }
208   }
209 ?>