From 5e25b738cf2e4a604fde726fd8391981c4e8a49e Mon Sep 17 00:00:00 2001 From: Mike Little Date: Wed, 30 Jul 2003 23:44:08 +0000 Subject: [PATCH] Removed mysql direct calls git-svn-id: https://develop.svn.wordpress.org/trunk@282 602fd350-edb4-49c9-b593-d223f7449a82 --- b2-include/b2functions.php | 4 ++-- b2-include/b2template.functions.php | 17 ++++++++++------- wp-admin/b2categories.php | 15 +++++---------- wp-admin/b2edit.showposts.php | 22 +++++++++------------- wp-admin/b2profile.php | 2 +- 5 files changed, 27 insertions(+), 33 deletions(-) diff --git a/b2-include/b2functions.php b/b2-include/b2functions.php index e32e201264..74dcedc144 100644 --- a/b2-include/b2functions.php +++ b/b2-include/b2functions.php @@ -519,7 +519,7 @@ function get_postdata($postid) { return $postdata; } -function get_postdata2($postid=0) { // less flexible, but saves mysql queries +function get_postdata2($postid=0) { // less flexible, but saves DB queries global $post; $postdata = array ( 'ID' => $post->ID, @@ -537,7 +537,7 @@ function get_postdata2($postid=0) { // less flexible, but saves mysql queries return $postdata; } -function get_commentdata($comment_ID,$no_cache=0) { // less flexible, but saves mysql queries +function get_commentdata($comment_ID,$no_cache=0) { // less flexible, but saves DB queries global $postc,$id,$commentdata,$tablecomments,$querycount, $wpdb; if ($no_cache) { $myrow = $wpdb->get_row("SELECT * FROM $tablecomments WHERE comment_ID = $comment_ID", ARRAY_A); diff --git a/b2-include/b2template.functions.php b/b2-include/b2template.functions.php index bdb48ed7c6..b4e796f18d 100644 --- a/b2-include/b2template.functions.php +++ b/b2-include/b2template.functions.php @@ -717,18 +717,21 @@ function next_posts($max_page = 0) { // original by cfactor at cooltux.org } function next_posts_link($label='Next Page >>', $max_page=0) { - global $p, $paged, $result, $request, $posts_per_page, $what_to_show; + global $p, $paged, $result, $request, $posts_per_page, $what_to_show, $wpdb; if ($what_to_show == 'paged') { if (!$max_page) { $nxt_request = $request; + //if the query includes a limit clause, call it again without that + //limit clause! if ($pos = strpos(strtoupper($request), 'LIMIT')) { $nxt_request = substr($request, 0, $pos); } - $nxt_result = mysql_query($nxt_request); - $numposts = mysql_num_rows($nxt_result); + $nxt_result = $wpdb->query($nxt_request); + $numposts = $wpdb->num_rows; $max_page = ceil($numposts / $posts_per_page); } - if (!$paged) $paged = 1; + if (!$paged) + $paged = 1; $nextpage = intval($paged) + 1; if (empty($p) && (empty($paged) || $nextpage <= $max_page)) { echo '$cat_name"); + $wpdb->query("INSERT INTO $tablecategories (cat_ID,cat_name) VALUES ('0', '$cat_name')"); header('Location: b2categories.php'); @@ -68,12 +67,9 @@ case 'Delete': if ($user_level < 3) die ('Cheatin’ uh?'); - - $query = "DELETE FROM $tablecategories WHERE cat_ID = $cat_ID"; - $result = mysql_query($query) or die("Couldn't delete category $cat_name".mysql_error()); - - $query = "UPDATE $tableposts SET post_category='1' WHERE post_category='$cat_ID'"; - $result = mysql_query($query) or die("Couldn't reset category on posts where category was $cat_name"); + + $wpdb->query("DELETE FROM $tablecategories WHERE cat_ID = $cat_ID"); + $wpdb->query("UPDATE $tableposts SET post_category='1' WHERE post_category='$cat_ID'"); header('Location: b2categories.php'); @@ -113,8 +109,7 @@ case 'editedcat': $cat_name = addslashes($HTTP_POST_VARS["cat_name"]); $cat_ID = addslashes($HTTP_POST_VARS["cat_ID"]); - $query = "UPDATE $tablecategories SET cat_name='$cat_name' WHERE cat_ID = $cat_ID"; - $result = mysql_query($query) or die("Couldn't edit category $cat_name: ".mysql_error()); + $wpdb->query("UPDATE $tablecategories SET cat_name='$cat_name' WHERE cat_ID = $cat_ID"); header('Location: b2categories.php'); diff --git a/wp-admin/b2edit.showposts.php b/wp-admin/b2edit.showposts.php index 5060707e14..93dca8bb1f 100644 --- a/wp-admin/b2edit.showposts.php +++ b/wp-admin/b2edit.showposts.php @@ -148,10 +148,9 @@ if ($i == "ASC") if ($archive_mode == "monthly") { echo ""; $archive_day_date_format = "Y/m/d"; - $arc_sql="SELECT DISTINCT YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) FROM $tableposts ORDER BY post_date DESC"; $querycount++; - $arc_result=mysql_query($arc_sql) or die($arc_sql."
".mysql_error()); - while($arc_row = mysql_fetch_array($arc_result)) { + $arc_result=$wpdb->get_results("SELECT DISTINCT YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date) FROM $tableposts ORDER BY post_date DESC", ARRAY_A); + foreach ($arc_result as $arc_row) { $arc_year = $arc_row["YEAR(post_date)"]; $arc_month = $arc_row["MONTH(post_date)"]; $arc_dayofmonth = $arc_row["DAYOFMONTH(post_date)"]; @@ -180,11 +178,10 @@ if ($i == "ASC") $archive_week_start_date_format = "Y/m/d"; $archive_week_end_date_format = "Y/m/d"; $archive_week_separator = " - "; - $arc_sql="SELECT DISTINCT YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date), WEEK(post_date) FROM $tableposts ORDER BY post_date DESC"; $querycount++; - $arc_result=mysql_query($arc_sql) or die($arc_sql."
".mysql_error()); + $arc_result=$wpdb->geT_results("SELECT DISTINCT YEAR(post_date), MONTH(post_date), DAYOFMONTH(post_date), WEEK(post_date) FROM $tableposts ORDER BY post_date DESC", ARRAY_A); $arc_w_last = ''; - while($arc_row = mysql_fetch_array($arc_result)) { + foreach ($arc_result as $arc_row) { $arc_year = $arc_row["YEAR(post_date)"]; $arc_w = $arc_row["WEEK(post_date)"]; if ($arc_w != $arc_w_last) { @@ -201,10 +198,9 @@ if ($i == "ASC") } elseif ($archive_mode == "postbypost") { echo ''; echo '