Support » Fixing WordPress » Not a valid MySQL-Link resource in wp-db.php

  • I am working on utility that imports posts from Joomla to WordPress. The code is kept in a sub-folder inside the WP root. The PHP has the following code, but I get the following error when I run it:

    Code:

    require_once('../wp-config.php');
    require('../wp-blog-header.php');
    require_once ('../wp-includes/functions.php');
    
    $my_post = array();
    $my_post['post_title'] = 'title';
    $my_post['post_content'] = 'content';
    $my_post['post_status'] = 'publish';
    $my_post['post_author'] = $ID;
    $my_post['post_date'] = '<date>';
    $my_post['post_category'] = array($wpsection);
    $my_post['post_name'] = $post_name;
    $my_post['post_excerpt'] = 'excerpt text';
    
    // Insert the post into the database
    $post_id = wp_insert_post( $my_post );

    Error:

    Warning: mysql_error(): 9 is not a valid MySQL-Link resource in C:\xampplite\htdocs\wp27nirantar\wp-includes\wp-db.php on line 685
    Warning: mysql_error(): 9 is not a valid MySQL-Link resource in C:\xampplite\htdocs\wp27nirantar\wp-includes\wp-db.php on line 685
    Warning: mysql_affected_rows(): 9 is not a valid MySQL-Link resource in C:\xampplite\htdocs\wp27nirantar\wp-includes\wp-db.php on line 691
    Warning: mysql_insert_id(): 9 is not a valid MySQL-Link resource in C:\xampplite\htdocs\wp27nirantar\wp-includes\wp-db.php on line 694

Viewing 11 replies - 1 through 11 (of 11 total)
  • No takers? 🙁

    whooami

    (@whooami)

    Member

    turn on debugging. or echo back the mysql query.

    Facing the same kind of problem..
    Has anyone found the solution????

    whooami

    (@whooami)

    Member

    turn on debugging. or echo back the mysql query.

    I tried that… I am trying to open another separate database. It works fine and i get the required result from that database also. But after accessing that database executing any query to wordpress database generates that error !!!

    whooami

    (@whooami)

    Member

    thats right, thats because youre not closing the other connection. MySQL needs to be told when it is making a new connection.

    use the new_link parameter.

    http://us.php.net/function.mysql-connect

    and ffr, thats not the same kind of problem.

    dude i have checked many times.. i am closing that another connection properly. If i dont use that other database it works perfectly fine. But after using that database it generates that error.

    $dbhost1 = ‘localhost’;
    $dbuser1 = ‘xxxx’;
    $dbpass1 = ‘xxxx’;
    $conn1 = mysql_connect($dbhost1, $dbuser1, $dbpass1) or die(‘Error connecting to mysql’);
    $dbname1 = ‘xxxx’;
    mysql_select_db($dbname1);

    $query = “SELECT email FROM users where id= ‘”.$login.”‘”;
    $result = mysql_query($query);
    $emailidArray = mysql_fetch_array($result);
    $email = $emailidArray[0];
    mysql_close($conn1);

    hey thanks man..
    new_link parameter worked perfectly fine..
    Thanks 🙂

    whooami

    (@whooami)

    Member

    im not a man. surprise surprise — girls know shit too.

    i dont mind who u are.. i got my problem solved.
    thanks.

Viewing 11 replies - 1 through 11 (of 11 total)
  • The topic ‘Not a valid MySQL-Link resource in wp-db.php’ is closed to new replies.