Skip to content
This repository was archived by the owner on Dec 6, 2019. It is now read-only.

Commit d3e30a2

Browse files
committed
cleanup mysql_* to mysqli_*
1 parent 49fd837 commit d3e30a2

File tree

2 files changed

+47
-78
lines changed

2 files changed

+47
-78
lines changed
Lines changed: 46 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<?php
22
/**
33
* Copyright (c) 2010 Nabeel Shahzad
4-
*
4+
*
55
* Permission is hereby granted, free of charge, to any person obtaining a copy
66
* of this software and associated documentation files (the "Software"), to deal
77
* in the Software without restriction, including without limitation the rights
88
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99
* copies of the Software, and to permit persons to whom the Software is
1010
* furnished to do so, subject to the following conditions:
11-
*
11+
*
1212
* The above copyright notice and this permission notice shall be included in
1313
* all copies or substantial portions of the Software.
1414
@@ -25,7 +25,7 @@
2525
* @link http://github.com/nshahzad/ezdb
2626
* @license MIT License
2727
*/
28-
28+
2929
/**
3030
* MySQLi implementation for ezDB
3131
* By Nabeel Shahzad
@@ -48,26 +48,26 @@ class ezDB_mysqli extends ezDB_Base
4848
public function __construct($dbuser='', $dbpassword='', $dbname='', $dbhost='localhost')
4949
{
5050
if($dbname == '') return false;
51-
51+
5252
parent::__construct();
53-
53+
5454
if($this->connect($dbuser, $dbpassword, $dbhost))
5555
{
5656
return $this->select($dbname);
5757
}
58-
58+
5959
return false;
6060
}
61-
61+
6262
/**
6363
* Explicitly close the connection on destruct
6464
*/
65-
65+
6666
public function __destruct()
6767
{
6868
$this->close();
6969
}
70-
70+
7171
/**
7272
* Connects to database immediately, unless $dbname is blank
7373
*
@@ -81,8 +81,8 @@ public function __destruct()
8181
public function quick_connect($dbuser='', $dbpassword='', $dbname='', $dbhost='localhost')
8282
{
8383
$this->__construct($dbuser, $dbpassword, $dbname, $dbhost);
84-
}
85-
84+
}
85+
8686
/**
8787
* Connect to MySQL, but not to a database
8888
*
@@ -95,12 +95,12 @@ public function quick_connect($dbuser='', $dbpassword='', $dbname='', $dbhost='l
9595
public function connect($dbuser='', $dbpassword='', $dbhost='localhost')
9696
{
9797
$this->dbh = new mysqli($dbhost, $dbuser, $dbpassword);
98-
98+
9999
if(mysqli_connect_errno() != 0)
100100
{
101101
if($this->throw_exceptions)
102102
throw new ezDB_Error(mysqli_connect_error(), mysqli_connect_errno());
103-
103+
104104
$this->register_error(mysqli_connect_error(), mysqli_connect_errno());
105105
return false;
106106
}
@@ -109,10 +109,10 @@ public function connect($dbuser='', $dbpassword='', $dbhost='localhost')
109109
$this->clear_errors();
110110
return true;
111111
}
112-
112+
113113
return true;
114114
}
115-
115+
116116
/**
117117
* Select a MySQL Database
118118
*
@@ -128,22 +128,22 @@ public function select($dbname='')
128128
throw new ezDB_Error('No database name', -1);
129129
$this->register_error('No database name specified!');
130130
}
131-
131+
132132
// Must have an active database connection
133133
if(!$this->dbh)
134134
{
135135
if($this->throw_exceptions)
136136
throw new ezDB_Error(mysqli_connect_error(), mysqli_connect_errno());
137-
137+
138138
$this->register_error('Can\'t select database, invalid or inactive connection', -1);
139139
return false;
140140
}
141-
141+
142142
if(!$this->dbh->select_db($dbname))
143143
{
144144
if($this->throw_exceptions)
145145
throw new ezDB_Error($this->dbh->error, $this->dbh->errno);
146-
146+
147147
$this->register_error($this->dbh->error, $this->dbh->errno);
148148
return false;
149149
}
@@ -152,18 +152,18 @@ public function select($dbname='')
152152
$this->clear_errors();
153153
return true;
154154
}
155-
155+
156156
return true;
157157
}
158-
158+
159159
/**
160160
* Close the database connection
161161
*/
162162
public function close()
163163
{
164164
return @$this->dbh->close();
165165
}
166-
166+
167167
/**
168168
* Format a mySQL string correctly for safe mySQL insert
169169
* (no matter if magic quotes are on or not)
@@ -176,7 +176,7 @@ public function escape($str)
176176
{
177177
return $this->dbh->real_escape_string($str);
178178
}
179-
179+
180180
/**
181181
* Returns the DB specific timestamp function (Oracle: SYSDATE, MySQL: NOW())
182182
*
@@ -187,7 +187,7 @@ public function sysdate()
187187
{
188188
return 'NOW()';
189189
}
190-
190+
191191
/**
192192
* Run the SQL query, and get the result. Returns false on failure
193193
* Check $this->error() and $this->errno() functions for any errors
@@ -196,71 +196,71 @@ public function sysdate()
196196
* @param string $query SQL Query
197197
* @return mixed Return values
198198
*
199-
*/
199+
*/
200200
public function query($query)
201201
{
202202
// Initialise return
203203
$return_val = true;
204-
204+
205205
// Flush cached values..
206206
$this->flush();
207-
207+
208208
// For reg expressions
209209
$query = trim($query);
210-
210+
211211
// Log how the function was called
212212
$this->func_call = "\$db->query(\"$query\")";
213-
213+
214214
// Keep track of the last query for debug..
215215
$this->last_query = $query;
216-
216+
217217
// Count how many queries there have been
218218
$this->num_queries++;
219-
219+
220220
// Use core file cache function
221221
if($cache = $this->get_cache($query))
222222
{
223223
return $cache;
224224
}
225-
225+
226226
// If there is no existing database connection then try to connect
227227
if ( ! $this->dbh )
228228
{
229229
if($this->throw_exceptions)
230230
throw new ezDB_Error($this->dbh->error, $this->dbh->errno);
231-
231+
232232
$this->register_error('There is no active database connection!');
233233
return false;
234234
}
235-
235+
236236
// Perform the query via std mysql_query function..
237237
$result = $this->dbh->query($query);
238238

239239
if($result === false)
240240
{
241241
if($this->throw_exceptions)
242242
throw new ezDB_Error($this->dbh->error, $this->dbh->errno);
243-
243+
244244
$this->register_error($this->dbh->error, $this->dbh->errno);
245245
}
246246
else
247247
{
248248
$this->clear_errors();
249249
}
250-
250+
251251
// Query was an insert, delete, update, replace
252252
$is_insert = false;
253253
if (preg_match("/^(insert|delete|update|replace)\s+/i",$query))
254254
{
255255
$this->rows_affected = $this->dbh->affected_rows;
256256
$this->num_rows = $this->rows_affected;
257-
257+
258258
if($this->dbh->insert_id > 0)
259259
{
260260
$this->insert_id = $this->dbh->insert_id;
261261
$is_insert = true;
262262
}
263-
263+
264264
// Return number of rows affected
265265
$return_val = $this->rows_affected;
266266
}
@@ -270,64 +270,33 @@ public function query($query)
270270
// Take note of column info
271271
$num_rows = 0;
272272
if($result instanceof MySQLi_Result)
273-
{
273+
{
274274
$this->col_info = $result->fetch_fields();
275-
275+
276276
// Store Query Results
277277
while($row = $result->fetch_object())
278278
{
279279
$this->last_result[$num_rows] = $row;
280280
$num_rows++;
281281
}
282-
282+
283283
$result->close();
284284
}
285-
285+
286286
// Log number of rows the query returned
287287
$this->rows_affected = $num_rows;
288288
$this->num_rows = $num_rows;
289-
289+
290290
// Return number of rows selected
291291
$return_val = $this->num_rows;
292292
}
293-
293+
294294
// disk caching of queries
295295
$this->store_cache($query,$is_insert);
296-
296+
297297
// If debug ALL queries
298298
$this->trace || $this->debug_all ? $this->debug() : null ;
299-
299+
300300
return $return_val;
301301
}
302-
303-
304-
/* this is mysqli only
305-
* incomplete implementation
306-
*//*
307-
function execute($query, $params)
308-
{
309-
if($this->mysql_version!=5 || $query == '' || $params == '')
310-
return;
311-
312-
$stmt = $this->dbh->stmt_init();
313-
if(!$stmt->prepare($query))
314-
return false;
315-
316-
//bind our parameters
317-
while(list($key, $value) = each($params))
318-
{
319-
if(is_double($value))
320-
$type = 'd';
321-
elseif(is_integer($value) || is_numeric($value))
322-
$type = 'i';
323-
else
324-
$type = 's';
325-
326-
$stmt->bind_param($type, $value);
327-
}
328-
329-
$stmt->execute();
330-
331-
332-
}*/
333302
}

install/Installer.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ public static function RegisterInstall($version = '')
362362
$params->addChild('email', SettingsData::GetSettingValue('ADMIN_EMAIL'));
363363
$params->addChild('version', $version);
364364
$params->addChild('php', phpversion());
365-
$params->addChild('mysql', @mysql_get_server_info());
365+
$params->addChild('mysql', @mysqli_get_server_info());
366366
$params->addChild('ext', $ext);
367367

368368
$url = 'http://api.phpvms.net/register';

0 commit comments

Comments
 (0)