WordPress.org

Support

Support » How-To and Troubleshooting » [Resolved] WP 3.0 – Database access outside wp loaded files

[Resolved] WP 3.0 – Database access outside wp loaded files

  • 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

Viewing 2 replies - 1 through 2 (of 2 total)
  • Turns out my syntax was wrong. All is well, I fixed it by establishing my own connection using the information in wp-config.php!

    //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');
    }
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘[Resolved] WP 3.0 – Database access outside wp loaded files’ is closed to new replies.
Skip to toolbar