WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] WP 3.0 - Database access outside wp loaded files (3 posts)

  1. victheone
    Member
    Posted 2 years ago #

    I've been having a problem dealing with accessing the MySQL "wordpress" database from a php script that is not loaded on-screen. My vision is that the displayed page (loaded in the wordpress content wrapper with the header) will make an AJAX request to an external DB interface script (also PHP) and that script will modify the database. So far, though, I haven't been able to get my external script to access the database. I've tried including the files associated with the $wpdb global class to no avail. I've more recently tried

    include_once(WP_PATH."/wp-config.php");

    and then attempted to create my own connection using mysql_connect(). This has also failed. I'm really not sure what to do in order to get the functionality I need.

    Just for some background, the reason I want to do this is so that I can have a "delete" button in a list of database values, but not have to load a separate page. I'm envisioning someone clicking delete, and then confirming the operation using javascript, making the AJAX "delete" request to my DB script, and then using jQuery to remove the deleted item from the page. No page loading whatsoever.

    Thanks for any help you can offer.

    -RD

  2. victheone
    Member
    Posted 2 years ago #

    Turns out my syntax was wrong. All is well, I fixed it by establishing my own connection using the information in wp-config.php!

  3. KwarK
    Member
    Posted 2 years ago #

    //Wordpress deprecated
    
    ini_set('display_errors','off');
    
    //Global WordPress
    
    global $wpdb;
    
    if(!isset($wpdb))
    {
        require_once('../../../wp-config.php');
        require_once('../../../wp-load.php');
        require_once('../../../wp-includes/wp-db.php');
    }

Topic Closed

This topic has been closed to new replies.

About this Topic