Skip to content

Commit 8f1296a

Browse files
committed
merge to switch to mysqli (this breaks PHP4 support. RIP.)
2 parents bcd54d2 + 5eb4f05 commit 8f1296a

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

phpFlickr.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -82,27 +82,27 @@ function enableCache ($type, $connection, $cache_expire = 600, $table = 'flickr_
8282
if ($type == 'db') {
8383
if ( preg_match('|mysql://([^:]*):([^@]*)@([^/]*)/(.*)|', $connection, $matches) ) {
8484
//Array ( [0] => mysql://user:password@server/database [1] => user [2] => password [3] => server [4] => database )
85-
$db = mysql_connect($matches[3], $matches[1], $matches[2]);
86-
mysql_select_db($matches[4], $db);
85+
$db = mysqli_connect($matches[3], $matches[1], $matches[2]);
86+
mysqli_query($db, "USE $matches[4]");
8787

8888
/*
8989
* If high performance is crucial, you can easily comment
9090
* out this query once you've created your database table.
9191
*/
92-
mysql_query("
92+
mysqli_query($db, "
9393
CREATE TABLE IF NOT EXISTS `$table` (
9494
`request` CHAR( 35 ) NOT NULL ,
9595
`response` MEDIUMTEXT NOT NULL ,
9696
`expiration` DATETIME NOT NULL ,
9797
INDEX ( `request` )
98-
) TYPE = MYISAM
99-
", $db);
98+
)
99+
");
100100

101-
$result = mysql_query("SELECT COUNT(*) FROM $table", $db);
102-
$result = mysql_fetch_row($result);
101+
$result = mysqli_query($db, "SELECT COUNT(*) FROM $table");
102+
$result = mysqli_fetch_row($result);
103103
if ( $result[0] > $this->max_cache_rows ) {
104-
mysql_query("DELETE FROM $table WHERE expiration < DATE_SUB(NOW(), INTERVAL $cache_expire second)", $db);
105-
mysql_query('OPTIMIZE TABLE ' . $this->cache_table, $db);
104+
mysqli_query($db, "DELETE FROM $table WHERE expiration < DATE_SUB(NOW(), INTERVAL $cache_expire second)");
105+
mysqli_query($db, 'OPTIMIZE TABLE ' . $this->cache_table);
106106
}
107107
$this->cache = 'db';
108108
$this->cache_db = $db;
@@ -141,9 +141,9 @@ function getCached ($request)
141141
$this->cache_key = $reqhash;
142142
$this->cache_request = $request;
143143
if ($this->cache == 'db') {
144-
$result = mysql_query("SELECT response FROM " . $this->cache_table . " WHERE request = '" . $reqhash . "' AND DATE_SUB(NOW(), INTERVAL " . (int) $this->cache_expire . " SECOND) < expiration", $this->cache_db);
145-
if ( mysql_num_rows($result) ) {
146-
$result = mysql_fetch_assoc($result);
144+
$result = mysqli_query($this->cache_db, "SELECT response FROM " . $this->cache_table . " WHERE request = '" . $reqhash . "' AND DATE_SUB(NOW(), INTERVAL " . (int) $this->cache_expire . " SECOND) < expiration");
145+
if ( mysqli_num_rows($result) ) {
146+
$result = mysqli_fetch_assoc($result);
147147
return $result['response'];
148148
} else {
149149
return false;
@@ -174,14 +174,14 @@ function cache ($request, $response)
174174
$reqhash = md5(serialize($request));
175175
if ($this->cache == 'db') {
176176
//$this->cache_db->query("DELETE FROM $this->cache_table WHERE request = '$reqhash'");
177-
$result = mysql_query("SELECT COUNT(*) FROM " . $this->cache_table . " WHERE request = '" . $reqhash . "'", $this->cache_db);
178-
$result = mysql_fetch_row($result);
177+
$result = mysqli_query($this->cache_db, "SELECT COUNT(*) FROM " . $this->cache_table . " WHERE request = '" . $reqhash . "'");
178+
$result = mysqli_fetch_row($result);
179179
if ( $result[0] ) {
180180
$sql = "UPDATE " . $this->cache_table . " SET response = '" . str_replace("'", "''", $response) . "', expiration = '" . strftime("%Y-%m-%d %H:%M:%S") . "' WHERE request = '" . $reqhash . "'";
181-
mysql_query($sql, $this->cache_db);
181+
mysqli_query($this->cache_db, $sql);
182182
} else {
183183
$sql = "INSERT INTO " . $this->cache_table . " (request, response, expiration) VALUES ('$reqhash', '" . str_replace("'", "''", $response) . "', '" . strftime("%Y-%m-%d %H:%M:%S") . "')";
184-
mysql_query($sql, $this->cache_db);
184+
mysqli_query($this->cache_db, $sql);
185185
}
186186
} elseif ($this->cache == "fs") {
187187
$file = $this->cache_dir . "/" . $reqhash . ".cache";

0 commit comments

Comments
 (0)