Announcement

Collapse
No announcement yet.

MySQL Query Not Going Through

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • MySQL Query Not Going Through

    Due to human error, the contents of one account was merged into another account. (For illustrations' sake, let's say the old account is "Bob" and the account "Bob" was merged into is "Mike".) Fortunately, I have acquired the post IDs of Bob from an older backup. So I made a PHP script to change Bob's post IDs (which were changed to Mike) back to Bob. Here's the code:

    PHP Code:
    error_reporting(E_ALL);

    if ( 
    == )
    {
        
    $ids "1,2,6,9"// the post ids, comma delimited
    }

    // of course, I took out the database info
    $dbx mysql_connect("""""") or die(mysql_error());
    mysql_select_db("") or die(mysql_error());

    $id_x explode(","$ids); // the exploded post ids

    $c 1// a counter, just to control the script for now
    // loop through each ID
    foreach( $id_x as $key => $post_id )
    {
        
    mysql_query("UPDATE vb_3post SET userid = 1 WHERE postid = '".$post_id."' LIMIT 1") or die(mysql_error());

          
    // for debug
        
    echo("<br>Post: ".$post_id.", changed: ".mysql_affected_rows() );
        if ( 
    $c == // if we've attempted to change five IDs
        
    {
            break; 
    // stop
        
    }
        
    $c++; // increment the counter

    This outputs something like:

    Code:
    Post: 1, changed: 0
    Post: 2, changed: 0
    Post: 6, changed: 0
    etc. etc. etc...
    No MySQL or PHP errors are displayed. I know there's something stupid I'm overlooking in the query, but what is it?

  • #2
    If you can capture the MySQL error then you can find out the problem.

    "vb_3post" looks suspicious. A more common prefixed table name would be "vb3_post". That might be the problem.

    Comment


    • #3
      Jake,

      Unfortunately, no MySQL error is returned when I try the script. Also, I tried running a query the script would generate by hand, and it didn't return any errors either.

      Also, vb_3 really is our prefix.

      Comment


      • #4
        would this query by itself do the trick?
        UPDATE vb_3post SET userid = '2514' WHERE postid = '1609'

        Comment


        • #5
          You can capture the error somehow, but I don't know the PHP code for it. I always work within the vBulletin API which has code to handle errors. I have never done it using raw MySQL functions.

          That query looks valid. The single quotes are not required, but they shouldn't hurt.

          Comment

          widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.
          Working...
          X