Removed mysql direct calls

git-svn-id: https://develop.svn.wordpress.org/trunk@282 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Mike Little 2003-07-30 23:44:08 +00:00
parent 210fd94760
commit 5e25b738cf
5 changed files with 27 additions and 33 deletions

View File

@ -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);

View File

@ -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 '<a href="';
@ -774,14 +777,14 @@ function previous_posts_link($label='<< Previous Page') {
}
function posts_nav_link($sep=' :: ', $prelabel='<< Previous Page', $nxtlabel='Next Page >>') {
global $p, $what_to_show, $request, $posts_per_page;
global $p, $what_to_show, $request, $posts_per_page, $wpdb;
if (empty($p) && ($what_to_show == 'paged')) {
$nxt_request = $request;
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 ($max_page > 1) {
previous_posts_link($prelabel);

View File

@ -47,8 +47,7 @@ case 'addcat':
$cat_name=addslashes($HTTP_POST_VARS["cat_name"]);
$query = "INSERT INTO $tablecategories (cat_ID,cat_name) VALUES ('0', '$cat_name')";
$result = mysql_query($query) or die("Couldn't add category <b>$cat_name</b>");
$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&#8217; uh?');
$query = "DELETE FROM $tablecategories WHERE cat_ID = $cat_ID";
$result = mysql_query($query) or die("Couldn't delete category <b>$cat_name</b>".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 <b>$cat_name</b>");
$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 <b>$cat_name</b>: ".mysql_error());
$wpdb->query("UPDATE $tablecategories SET cat_name='$cat_name' WHERE cat_ID = $cat_ID");
header('Location: b2categories.php');

View File

@ -148,10 +148,9 @@ if ($i == "ASC")
if ($archive_mode == "monthly") {
echo "<select name=\"m\" style=\"width:120px;\">";
$arc_sql="SELECT DISTINCT YEAR(post_date), MONTH(post_date) FROM $tableposts ORDER BY post_date DESC";
$querycount++;
$arc_result=mysql_query($arc_sql) or die($arc_sql."<br />".mysql_error());
while($arc_row = mysql_fetch_array($arc_result)) {
$arc_result=$wpdb->get_results("SELECT DISTINCT YEAR(post_date), MONTH(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)"];
echo "<option value=\"$arc_year".zeroise($arc_month,2)."\">";
@ -161,10 +160,9 @@ if ($i == "ASC")
} elseif ($archive_mode == "daily") {
echo "<select name=\"d\" style=\"width:120px;\">";
$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."<br />".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."<br />".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 '<input type="hidden" name="more" value="1" />';
echo '<select name="p" style="width:120px;">';
$requestarc = " SELECT ID,post_date,post_title FROM $tableposts ORDER BY post_date DESC";
$querycount++;
$resultarc = mysql_query($requestarc);
while($row=mysql_fetch_object($resultarc)) {
$querycount++;
$resultarc = $wpdb->get_results("SELECT ID,post_date,post_title FROM $tableposts ORDER BY post_date DESC");
foreach ($resultarc as $row) {
if ($row->post_date != "0000-00-00 00:00:00") {
echo "<option value=\"".$row->ID."\">";
if (strip_tags($row->post_title)) {

View File

@ -96,7 +96,7 @@ case 'update':
$query = "UPDATE $tableusers SET user_firstname='$newuser_firstname', ".$updatepassword."user_lastname='$newuser_lastname', user_nickname='$newuser_nickname', user_icq='$newuser_icq', user_email='$newuser_email', user_url='$newuser_url', user_aim='$newuser_aim', user_msn='$newuser_msn', user_yim='$newuser_yim', user_idmode='$newuser_idmode' WHERE ID = $user_ID";
$result = $wpdb->query($query);
if (!$result) {
die ("<strong>ERROR</strong>: couldn't update your profile... please contact the <a href=\"mailto:$admin_email\">webmaster</a> !<br /><br />$query<br /><br />".mysql_error());
die ("<strong>ERROR</strong>: couldn't update your profile... please contact the <a href=\"mailto:$admin_email\">webmaster</a> !<br /><br />$query<br /><br />");
}
?>