From 459e929311d8806f604c0b914ba4b37aa731fbfc Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Mon, 8 Jan 2024 21:09:05 +0000 Subject: Migrated to mysqli --- .gitignore | 1 + comic.php | 13 ++- includes/db.php | 4 +- includes/fix_mysql.inc.php | 257 --------------------------------------------- includes/functions.php | 24 +++-- includes/update.php | 26 ++--- pages/archive.php | 20 ++-- pages/comic.php | 22 ++-- pages/random.php | 5 +- pages/season.php | 19 ++-- rss.php | 5 +- 11 files changed, 75 insertions(+), 321 deletions(-) create mode 100644 .gitignore delete mode 100755 includes/fix_mysql.inc.php diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..6a358f6 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +images/comics diff --git a/comic.php b/comic.php index 1e94abc..e8333bb 100755 --- a/comic.php +++ b/comic.php @@ -8,11 +8,14 @@ if (!isset($_GET['id'])) exit; } -$getcomic = "SELECT * FROM comics WHERE filename = \"" . mysqli_real_escape_string($mysql_conn, $_GET['id']) . ".png\""; -$getcomic2 = mysql_query($getcomic); -$getcomic3 = mysql_fetch_array($getcomic2); - -if ($getcomic3['filename'] != ($_GET['id'] . '.png')) +$getcomic = $mysql_conn->prepare("SELECT * FROM comics WHERE filename = ?"); +$real_filename = $_GET['id'] . ".png"; +$getcomic->bind_param("s", $real_filename); +$getcomic->execute(); +$getcomic2 = $getcomic->get_result(); +$getcomic3 = $getcomic2->fetch_assoc(); + +if ($getcomic3['filename'] != $real_filename) { header('Location: /'); exit; diff --git a/includes/db.php b/includes/db.php index 6554b8a..e2d67ee 100755 --- a/includes/db.php +++ b/includes/db.php @@ -1,9 +1,7 @@ diff --git a/includes/fix_mysql.inc.php b/includes/fix_mysql.inc.php deleted file mode 100755 index 8ff45bf..0000000 --- a/includes/fix_mysql.inc.php +++ /dev/null @@ -1,257 +0,0 @@ -= 0){ - mysqli_data_seek($result, $row); - $resultrow = (is_numeric($col)) ? mysqli_fetch_row($result) : mysqli_fetch_assoc($result); - if (isset($resultrow[$col])){ - return $resultrow[$col]; - } - } - return false; - } - - function mysql_escape_string($s, $link_identifier = null){ - global $global_link_identifier; - if($link_identifier == null) { - $link_identifier = $global_link_identifier; - } - return mysqli_real_escape_string($link_identifier, $s); - } - - function mysql_fetch_field($result, $i = null) { - if ($i === null) { - return mysqli_fetch_field($result); - } - return mysqli_fetch_field_direct($result, $i); - } - - function mysql_field_name($result, $i) { - return mysqli_fetch_field_direct($result, $i)->name; - } - - function mysql_field_type($result, $i){ - return mysqli_fetch_field_direct($result, $i)->type; - } - - function mysql_field_len($result, $i){ - return mysqli_fetch_field_direct($result, $i)->length; - } - - function mysql_num_fields($result){ - return mysqli_num_fields($result); - } - - function mysql_free_result($result) { - return mysqli_free_result($result); - } - - function mysql_get_server_info($link_identifier = null){ - global $global_link_identifier; - if($link_identifier == null) { - $link_identifier = $global_link_identifier; - } - return mysqli_get_server_info($link_identifier); - } - - function mysql_set_charset($csname, $link_identifier = null){ - global $global_link_identifier; - if($link_identifier == null) { - $link_identifier = $global_link_identifier; - } - return mysqli_set_charset($link_identifier, $csname); - } - - // aliases - function mysql(...$args){ return mysql_db_query(...$args); } - function mysql_createdb(...$args){ return mysql_create_db(...$args); } - function mysql_db_name(...$args){ return mysql_result(...$args); } - function mysql_dbname(...$args){ return mysql_result(...$args); } - function mysql_dropdb(...$args){ return mysql_drop_db(...$args); } - function mysql_fieldflags(...$args){ return mysql_field_flags(...$args); } - function mysql_fieldlen(...$args){ return mysql_field_len(...$args); } - function mysql_fieldname(...$args){ return mysql_field_name(...$args); } - function mysql_fieldtable(...$args){ return mysql_field_table(...$args); } - function mysql_fieldtype(...$args){ return mysql_field_type(...$args); } - function mysql_freeresult(...$args){ return mysql_free_result(...$args); } - function mysql_listdbs(...$args){ return mysql_list_dbs(...$args); } - function mysql_listfields(...$args){ return mysql_list_fields(...$args); } - function mysql_listtables(...$args){ return mysql_list_tables(...$args); } - function mysql_numfields(...$args){ return mysql_num_fields(...$args); } - function mysql_numrows(...$args){ return mysql_num_rows(...$args); } - function mysql_selectdb(...$args){ return mysql_select_db(...$args); } - - // TODO: those functions are not defined yet: - function mysql_client_encoding(){ trigger_error("mysql_client_encoding is not defined yet", E_USER_ERROR); } - function mysql_create_db(){ trigger_error("mysql_create_db is not defined yet", E_USER_ERROR); } - function mysql_drop_db(){ trigger_error("mysql_drop_db is not defined yet", E_USER_ERROR); } - function mysql_fetch_lengths(){ trigger_error("mysql_fetch_lengths is not defined yet", E_USER_ERROR); } - function mysql_field_flags(){ trigger_error("mysql_field_flags is not defined yet", E_USER_ERROR); } - function mysql_field_seek(){ trigger_error("mysql_field_seek is not defined yet", E_USER_ERROR); } - function mysql_field_table(){ trigger_error("mysql_field_table is not defined yet", E_USER_ERROR); } - function mysql_get_client_info(){ trigger_error("mysql_get_client_info is not defined yet", E_USER_ERROR); } - function mysql_get_host_info(){ trigger_error("mysql_get_host_info is not defined yet", E_USER_ERROR); } - function mysql_get_proto_info(){ trigger_error("mysql_get_proto_info is not defined yet", E_USER_ERROR); } - function mysql_info(){ trigger_error("mysql_info is not defined yet", E_USER_ERROR); } - function mysql_list_dbs(){ trigger_error("mysql_list_dbs is not defined yet", E_USER_ERROR); } - function mysql_list_fields(){ trigger_error("mysql_list_fields is not defined yet", E_USER_ERROR); } - function mysql_list_processes(){ trigger_error("mysql_list_processes is not defined yet", E_USER_ERROR); } - function mysql_tablename(){ trigger_error("mysql_tablename is not defined yet", E_USER_ERROR); } - function mysql_stat(){ trigger_error("mysql_stat is not defined yet", E_USER_ERROR); } - function mysql_thread_id(){ trigger_error("mysql_thread_id is not defined yet", E_USER_ERROR); } - function mysql_unbuffered_query(){ trigger_error("mysql_unbuffered_query is not defined yet", E_USER_ERROR); } -} diff --git a/includes/functions.php b/includes/functions.php index edb666b..e0a5ab8 100755 --- a/includes/functions.php +++ b/includes/functions.php @@ -2,9 +2,12 @@ function has_meta($id, $name) { - $getmeta = "SELECT * FROM meta WHERE comic_id = " . $id . " AND name = \"" . $name . "\""; - $getmeta2 = mysql_query($getmeta); - $getmeta3 = mysql_fetch_array($getmeta2); + global $mysql_conn; + $getmeta = $mysql_conn->prepare("SELECT * FROM meta WHERE comic_id = ? AND name = ?"); + $getmeta->bind_param("is", $id, $name); + $getmeta->execute(); + $getmeta2 = $getmeta->get_result(); + $getmeta3 = $getmeta2->fetch_assoc(); if ($getmeta3['name'] == $name) { @@ -16,18 +19,21 @@ function has_meta($id, $name) function get_meta($id, $name) { - $getmeta = "SELECT * FROM meta WHERE comic_id = " . $id . " AND name = \"" . $name . "\""; - $getmeta2 = mysql_query($getmeta); - $getmeta3 = mysql_fetch_array($getmeta2); + global $mysql_conn; + $getmeta = $mysql_conn->prepare("SELECT * FROM meta WHERE comic_id = ? AND name = ?"); + $getmeta->bind_param("is", $id, $name); + $getmeta->execute(); + $getmeta2 = $getmeta->get_result(); + $getmeta3 = $getmeta2->fetch_assoc(); return $getmeta3['value']; } function next_comic_id() { - $getcomic = "SELECT * FROM comics WHERE status = \"publish\" ORDER BY comic_id DESC LIMIT 0,1"; - $getcomic2 = mysql_query($getcomic); - $getcomic3 = mysql_fetch_array($getcomic2); + global $mysql_conn; + $getcomic = $mysql_conn->query("SELECT * FROM comics WHERE status = \"publish\" ORDER BY comic_id DESC LIMIT 0,1"); + $getcomic3 = $getcomic->fetch_assoc(); return ($getcomic3['comic_id']+1); } diff --git a/includes/update.php b/includes/update.php index 6c8d9ff..3f2fae1 100755 --- a/includes/update.php +++ b/includes/update.php @@ -1,27 +1,29 @@ query("SELECT * FROM config WHERE name = \"lastUpdated\""); +$getlast3 = $getlast->fetch_assoc(); $last = $getlast3['value']; if ($last != date('md')) { - $getpending = "SELECT * FROM comics WHERE status = \"pending\" ORDER BY id ASC LIMIT 0,1"; - $getpending2 = mysql_query($getpending); - $getpending3 = mysql_fetch_array($getpending2); + $getpending = $mysql_conn->query("SELECT * FROM comics WHERE status = \"pending\" ORDER BY id ASC LIMIT 0,1"); + $getpending3 = $getpending->fetch_assoc(); if (!empty($getpending3)) { $id = next_comic_id(); - $setcomic = "UPDATE comics SET status = \"publish\", comic_id = " . $id . " WHERE id = " . $getpending3['id']; - $setcomic2 = mysql_query($setcomic) or die($setcomic); + $setcomic = $mysql_conn->prepare("UPDATE comics SET status = \"publish\", comic_id = ? WHERE id = ?"); + $setcomic->bind_param("ii", $id, $getpending3['id']); + $setcomic->execute() or die($setcomic); - $insmeta = "INSERT INTO meta (comic_id,name,value) VALUES (" . $getpending3['id'] . ",\"pubDate\",\"" . date('Y-m-d H:i:s') . "\")"; - $insmeta2 = mysql_query($insmeta) or die($insmeta); + $insmeta = $mysql_conn->prepare("INSERT INTO meta (comic_id,name,value) VALUES (?,\"pubDate\",\"" . date('Y-m-d H:i:s') . "\")"); + $insmeta->bind_param("i", $getpending3['id']); + $insmeta->execute() or die($insmeta); - $setconfig = "UPDATE config SET value = \"" . date('md') . "\" WHERE name = \"lastUpdated\""; - $setconfig2 = mysql_query($setconfig); + $setconfig = $mysql_conn->prepare("UPDATE config SET value = ? WHERE name = \"lastUpdated\""); + $newdate = date('md'); + $setconfig->bind_param("s", $newdate); + $setconfig->execute(); } } diff --git a/pages/archive.php b/pages/archive.php index c5f0f52..114062c 100755 --- a/pages/archive.php +++ b/pages/archive.php @@ -10,25 +10,21 @@ query("SELECT * FROM seasons ORDER BY season_id ASC"); +foreach ($getseasons as $getseasons3) { - $getfc = "SELECT * FROM comics WHERE comic_id = " . $getseasons3['first_comic_id']; - $getfc2 = mysql_query($getfc); - $getfc3 = mysql_fetch_array($getfc2); + $getfc = $mysql_conn->query("SELECT * FROM comics WHERE comic_id = " . $getseasons3['first_comic_id']); + $getfc3 = $getfc->fetch_assoc(); if (!is_null($getseasons3['last_comic_id'])) { - $getlc = "SELECT * FROM comics WHERE comic_id = " . $getseasons3['last_comic_id']; - $getlc2 = mysql_query($getlc); - $getlc3 = mysql_fetch_array($getlc2); + $getlc = $mysql_conn->query("SELECT * FROM comics WHERE comic_id = " . $getseasons3['last_comic_id']); + $getlc3 = $getlc->fetch_assoc(); $count = $getseasons3['last_comic_id'] - ($getseasons3['first_comic_id']-1); } else { - $getcnt = "SELECT COUNT(*) FROM comics WHERE comic_id >= " . $getseasons3['first_comic_id']; - $getcnt2 = mysql_query($getcnt); - $getcnt3 = mysql_fetch_array($getcnt2); + $getcnt = $mysql_conn->query("SELECT COUNT(*) FROM comics WHERE comic_id >= " . $getseasons3['first_comic_id']); + $getcnt3 = $getcnt->fetch_assoc(); $count = $getcnt3[0]; } diff --git a/pages/comic.php b/pages/comic.php index 620a038..53b0538 100755 --- a/pages/comic.php +++ b/pages/comic.php @@ -2,12 +2,16 @@ if (isset($_GET['id']) && is_numeric($_GET['id'])) { - $getcomic = "SELECT * FROM comics WHERE comic_id = " . $_GET['id'] . " AND status = \"publish\""; + $getcomic = $mysql_conn->prepare("SELECT * FROM comics WHERE comic_id = ? AND status = \"publish\""); + $comic_id = $_GET['id']; + $getcomic->bind_param("i", $comic_id); + $getcomic->execute(); + $getcomic2 = $getcomic->get_result(); + $getcomic3 = $getcomic2->fetch_assoc(); } else { - $getcomic = "SELECT * FROM comics WHERE status = \"publish\" ORDER BY comic_id DESC LIMIT 0,1"; + $getcomic = $mysql_conn->query("SELECT * FROM comics WHERE status = \"publish\" ORDER BY comic_id DESC LIMIT 0,1"); + $getcomic3 = $getcomic->fetch_assoc(); } -$getcomic2 = mysql_query($getcomic); -$getcomic3 = mysql_fetch_array($getcomic2); $date = strtotime(get_meta($getcomic3['id'], 'pubDate')); @@ -64,9 +68,8 @@ if (has_meta($getcomic3['id'], 'link')) $id = $getcomic3['comic_id']; -$cntcomics = "SELECT COUNT(*) FROM comics WHERE status = \"publish\""; -$cntcomics2 = mysql_query($cntcomics); -$cntcomics3 = mysql_fetch_array($cntcomics2); +$cntcomics = $mysql_conn->query("SELECT COUNT(*) FROM comics WHERE status = \"publish\""); +$cntcomics3 = $cntcomics->fetch_assoc(); $all = $cntcomics3['COUNT(*)']; if ($id > 2) @@ -98,9 +101,8 @@ if ($id < $all) } } -$cntpending = "SELECT COUNT(*) FROM comics WHERE status = \"pending\""; -$cntpending2 = mysql_query($cntpending); -$cntpending3 = mysql_fetch_array($cntpending2); +$cntpending = $mysql_conn->query("SELECT COUNT(*) FROM comics WHERE status = \"pending\""); +$cntpending3 = $cntpending->fetch_assoc(); $numpending = $cntpending3['COUNT(*)']; ?> diff --git a/pages/random.php b/pages/random.php index 15d7758..049f151 100644 --- a/pages/random.php +++ b/pages/random.php @@ -1,8 +1,7 @@ query("SELECT * FROM comics WHERE status = \"publish\" ORDER BY RAND() LIMIT 1"); +$getcomic3 = $getcomic->fetch_assoc(); header('Location: http://pillowcase.fourisland.com/comic' . $getcomic3['comic_id'] . '.htm'); diff --git a/pages/season.php b/pages/season.php index 74568a0..f47ab13 100755 --- a/pages/season.php +++ b/pages/season.php @@ -2,9 +2,11 @@ if (is_numeric($_GET['season'])) { - $getseason = "SELECT * FROM seasons WHERE season_id = " . $_GET['season']; - $getseason2 = mysql_query($getseason); - $getseason3 = mysql_fetch_array($getseason2); + $getseason = $mysql_conn->prepare("SELECT * FROM seasons WHERE season_id = ?"); + $getseason->bind_param("i", $_GET['season']); + $getseason->execute(); + $getseason2 = $getseason->get_result(); + $getseason3 = $getseason2->fetch_assoc(); } if (isset($getseason3) && ($getseason3['season_id'] == $_GET['season'])) @@ -18,13 +20,16 @@ if (isset($getseason3) && ($getseason3['season_id'] == $_GET['season'])) if (!is_null($getseason3['last_comic_id'])) { - $getcomics = "SELECT * FROM comics WHERE status = \"publish\" AND comic_id >= " . $getseason3['first_comic_id'] . " AND comic_id <= " . $getseason3['last_comic_id'] . " ORDER BY comic_id ASC"; + $getcomics = $mysql_conn->prepare("SELECT * FROM comics WHERE status = \"publish\" AND comic_id >= ? AND comic_id <= ? ORDER BY comic_id ASC"); + $getcomics->bind_param("ii", $getseason3["first_comic_id"], $getseason3["last_comic_id"]); } else { - $getcomics = "SELECT * FROM comics WHERE status = \"publish\" AND comic_id >= " . $getseason3['first_comic_id'] . " ORDER BY comic_id ASC"; + $getcomics = $mysql_conn->prepare("SELECT * FROM comics WHERE status = \"publish\" AND comic_id >= ? ORDER BY comic_id ASC"); + $getcomics->bind_param("i", $getseason3["first_comic_id"]); } -$getcomics2 = mysql_query($getcomics); -while ($getcomics3 = mysql_fetch_array($getcomics2)) +$getcomics->execute(); +$getcomics2 = $getcomics->get_result(); +foreach ($getcomics2 as $getcomics3) { ?>
  • '); en-us query("SELECT * FROM comics WHERE status = \"publish\" ORDER BY comic_id DESC LIMIT 0,10"); +foreach ($getitems as $getitems3) { ?> -- cgit 1.4.1