• mdisanto

    (@mdisanto)


    I have a database that is entirely separate (though on same server) from wordpress and I am trying to pull information from it to display on the blog. I have a function that looks like this

    $db = mysql_connect(“hostname”, “username”, “password”) or die(“Check DB connection settings”);

    // stuff here

    mysql_select_db(“db_name”, $db);
    mysql_close($db);

    It doesn’t matter what I have in the middle, in fact I have it commented all out at the moment, as long as I invoke “mysql_connect” on the page, nothing else from WordPress loads correctly. Is there another way I’m supposed to do this? Thanks for your help!

Viewing 5 replies - 1 through 5 (of 5 total)
  • whooami

    (@whooami)

    Is there another way I’m supposed to do this?

    use the new_link parameter.

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

    Thread Starter mdisanto

    (@mdisanto)

    hmm I changed the line to

    $db = mysql_connect(“hostname”, “username”, “password”, true) or die(“Check DB connection settings”);

    but still having the same problem. Thanks for the quick response!

    whooami

    (@whooami)

    dunno then, its worked before.

    Thread Starter mdisanto

    (@mdisanto)

    also, the username and password are different from what wordpress is using to connect to the main wordpress db. According to the docs mysql_connect should open a new link by default anyway if the user/pass is different.

    I tried globalizing $wpdb and ->select’ing my database, then switching back to the wordpress db, no luck. I tried regular mysql_select_db, same thing. I tried creating a new instance of the wpdb class and using its constructor to connect to my database, but again, same thing. Any database calls after any mysql_connect fail.

    Thread Starter mdisanto

    (@mdisanto)

    for anyone curious, I was able to get it working by giving the wordpress database user privileges to the secondary database. Then I used mysql_query – which reuses the wordpress db link by default – and defined the database explicitly in the sql command “SELECT * FROM dbname.table”

    So, while I couldn’t figure out, and still dont understand why mysql_connect wasn’t working, this is one possible workaround.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘mysql_connect conflict’ is closed to new replies.