Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7039729
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:50:00+00:00 2026-05-28T01:50:00+00:00

I wrote this quick script which updates the database when moving the location of

  • 0

I wrote this quick script which updates the database when moving the location of the word press blog. The question:
It would be good if it showed how many rows have been updated. Is this possible?

 <?php
if(isset($_GET['confirm'])){

    // Load WordPress
    require_once('wp-load.php');

    // Form variables
    $site_was = $_GET['site_was'];
    $site_now = $_GET['site_now'];

    $db_queries = array(
        "UPDATE wp_options SET option_value = replace(option_value, '".$site_was."', '".$site_now."') WHERE option_name = 'home' OR option_name = 'siteurl'",
        "UPDATE wp_posts SET guid = REPLACE (guid, '".$site_was."', '".$site_now."')",
        "UPDATE wp_posts SET post_content = REPLACE (post_content, '".$site_was."', '".$site_now."')",
        "UPDATE wp_posts SET post_content = REPLACE (post_content, 'src=\"".$site_was."', 'src=\"".$site_now."')",
        "UPDATE wp_posts SET  guid = REPLACE (guid, '".$site_was."', '".$site_now."') WHERE post_type = 'attachment'",
        "UPDATE wp_postmeta SET meta_value = REPLACE (meta_value, '".$site_was."','".$site_now."')"
    );

    foreach ($db_queries as $sql) {
        $wpdb->query($sql);
    }

} else {
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
    <p>E.g http://examples.com or http://www.example.com/shop</p>
    <label>
        Site was:
        <input type="text" name="site_was" value="<?php if(isset($_GET['site_was'])) echo $_GET['site_was']?>" size="50" />
    </label>
    <br />
    <label>
        Site now:
        <input type="text" name="site_now" value="<?php if(isset($_GET['site_now'])) echo $_GET['site_now']?>" size="50" />
    </label>

    <input type="submit" name="confirm" value="Update Datebase" />
</form>
<?php } ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T01:50:01+00:00Added an answer on May 28, 2026 at 1:50 am

    You should be calling $wpdb->update() with the relevant table rows and data. That will return the number of affected rows.

    e.g.

    $rows = $wpdb->update( 
        'table', 
        array( 
            'column1' => 'value1',  // string
            'column2' => 'value2'   // integer (number) 
        ), 
        array( 'ID' => 1 ), 
        array( 
            '%s',   // value1
            '%d'    // value2
        ), 
        array( '%d' ) 
    );
    

    See here: http://codex.wordpress.org/Class_Reference/wpdb#UPDATE_rows

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote this script which counts occurrences of particular pattern in a given file.
I hope this is a quick question I hope. I need to write some
I wrote a quick script to download files using LWP::Simple library and its getstore()
Just a quick one - I wrote a php script recently that dynamically creates
So I wrote a Python script which does some simple stuff. It was originally
I wrote one script which gets an image url through JSONP, and then I
Hey guys.. Quick question: I wrote a simple JS that opens lightBox for image
I've wrote a quick PHP class to ease the access to a mysql database.
In my classes I often write a quick operator!= by returning !(*this == rhs)
I wrote this function that's supposed to do StringPadRight("Hello", 10, "0") -> "Hello00000" .

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.