WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Connecting to another mysql database (12 posts)

  1. pmulgrew
    Member
    Posted 4 years ago #

    Hi All,

    I am new to wordpress and having a bit of a problem.

    I am using wordpress as the blog/news section of my site but the rest of the site is independent from wordpress.

    what i am trying to do is connect to the mysql database i created for the rest of the site so i can display product categories etc from the database i created and display them in the template for the wordpress blog. but when i add my config files that connect to my database some wordpress features stop working. like archives, comments, blogroll links and wordpress categories.

    the main navigation of the site i am building is dependent on the database. does anyone know why this is happening or how to fix this.

  2. webjunk
    Member
    Posted 4 years ago #

    Maybe there is an issue with sharing the database? Somewhere you have created a conflict yourself. Does not sounds like a WP issue.

  3. MichaelH
    Member
    Posted 4 years ago #

    Not really answering your question, but noting that if you put those 'other' tables into the same database as your WordPress tables, it might be easier, and you can use the wpdb class to access that data.

  4. webjunk
    Member
    Posted 4 years ago #

    I first read it as trying to use a single database. Maybe we are both confused on what he is trying to do.

    pmulgrew:
    You wrote "when i add my config files that connect to my database" WHat config files and which database?
    Not sure how you have things configured. Maybe some code examples? Or layout of the structure? Somewhere it sounds like you have either code crossed or accessing the wrong database which is stopping WP functions. As I said before it does not sound like a WP issue but in your code. MichaelH had the best idea is if you use a single database.

  5. pmulgrew
    Member
    Posted 4 years ago #

    I could try adding the tables to the same database. I'd need to read up more on wordpress classes. This is my first time using wordpress and of course i had to make life hard for myself by doing things awkwardly.

    thanks for the suggestion MichaelH i will create a local backup of the databases and see if i can get something working.

  6. webjunk
    Member
    Posted 4 years ago #

    If you do a search in teh Docs area there is a document that has a complete breakdown of the database, classes, tables, etc. You might find that helpful.

  7. pmulgrew
    Member
    Posted 4 years ago #

    I got it working by combining the two databases. And even better i dont have to use the wordpress classes my config file works and i am able to use some plain ole php (mysql_query() etc etc) to get the data i need.

  8. MichaelH
    Member
    Posted 4 years ago #

    And even better i dont have to use the wordpress classes my config file works and i am able to use some plain ole php (mysql_query() etc etc) to get the data i need.

    Don't know that that is better ;)

    Marking resolved.

  9. Zaine
    Member
    Posted 4 years ago #

    I think I've got this same issue!

    I'm using $WPDB to save and read stuff in a plugin, but also attempting to connect to a database using standard mysql functions elsewhere.

    It appears that $WPDB is reusing the other database connection!!

    If I disconnect from the external database at any point, any other wordpress widgets (like archives etc) get upset about not being able to see the wordpress db.

  10. Zaine
    Member
    Posted 4 years ago #

    Worked out what was happening here. Details on the end of this post:

    http://wordpress.org/support/topic/296829?replies=3#post-1359860

  11. pyeager
    Member
    Posted 4 years ago #

    I have stumbled upon the same issue upon which Zaine has commented, but I'm having it in a different context. Here is a short description.

    1. Plugin A creates a new wpdb object to access a second database, using the following line within a PHP function:
    $lwpdb = new wpdb( $user, $pass, $db, $host );

    2. Plugin B attempts to reference the wordpress database via the wpdb object created by wordpress, using these lines within a function:
    global $wpdb;
    $sql = "select * from $mi_table_name";
    $results = $wpdb->get_results( $sql, ARRAY_A );

    3. Then the fun begins. Plugin B's query gets run against the database referenced by Plugin A. I know that this is happening by the error message, which clearly states that the query is failing due to lack of select privileges on Plugin A's database.

    This has to be either a bug or a failure to properly document the behavior of the wpdb object.

  12. pyeager
    Member
    Posted 4 years ago #

    New post on this topic at the link below, since there appears to be an actual bug.

    http://wordpress.org/support/topic/355262?replies=1#post-1362072

Topic Closed

This topic has been closed to new replies.

About this Topic