Accessing the database

Hi all.

If I wanted to access the database to place some info onto a non-WordPress php page, how would I do that?

I have some options in admin and would like to be able to pull that out of the database and place it into the page, which is in a plugin folder.

Also, would I just add this to the page as usual?
echo get_option('fbappid');

Thanks

  • Mason

    Hiya WP3,

    I'm a bit confused as to what you need to do, sorry.

    If I wanted to access the database to place some info onto a non-WordPress php page, how would I do that?

    This post, walks you through how to pull a WordPress post onto a standard html page. You should be able to adapt it to pull an option value:
    http://www.corvidworks.com/articles/wordpress-content-on-other-pages

    I have some options in admin and would like to be able to pull that out of the database and place it into the page, which is in a plugin folder.

    This is the part that confuses me a bit. It shouldn't matter where the page is located on your install (I'm assuming we're talking public facing html and not a page of your plugin) but I'm not sure putting a page in the plugin folder is the best idea.

    Also, would I just add this to the page as usual?
    echo get_option('fbappid');

    Hopefully the tutorial I linked to can help answer this for you. Basically you load WorPress, run your query, and then print the results wherever ya like on the page.

    If you need something more specific or if I've missed the mark completely let us know with a bit more detail and we'll give it another go.

    Thanks!

  • DavidM

    Hi WP3,

    Assuming you're building your own PHP page outside of WordPress that will connect to the WordPress database you can take a look at your wp-config.php file for all the details you need to communicate with your WordPress database.

    And the following reference should help you get the connection made.
    http://www.w3schools.com/PHP/php_mysql_connect.asp

    You'd have to actually be able to write to a page in your plugin folder in order for your final inquiry to work. The echo would merely echo the results of your option to the rendered html page you see. There's quite a bit more work to what you're doing but I think the link I posted provides details on the functions you'd need.

    And hopefully others around here have more to add. :slight_smile:

    Cheers,
    David

  • Moonworks

    ok, I have managed to get away from pulling the db into a seperate section of the site, and am keeping everythign in the plugins folder. However, I have one final question, which I hope somebody knows the answer to, because I'm starting to run out of hair to pull out.

    I have created an admin section where the user can add their Facebook app id & app secret, and I am tryign to pull it into a page that is in the plugins section of WordPress.

    This is part of the page with the code working, having the two sections hard-coded:

    $app_id = "195034203865645";
    $app_secret = "fc7c40fc1fd5f87f6ba7df1ab4105645";
    
    $facebook = new Facebook(array(
            'appId' => $app_id,
            'secret' => $app_secret,
            'cookie' => true
    ));

    However I just want to get the info from the db into the file.

    The two sections have the following names:

    fbappid
    fbappsecret

    I have tried various things, among them:

    $app_id = get_option('fbappid');
    $app_secret = get_option('fbappsecret');
    
    $facebook = new Facebook(array(
            'appId' => $app_id,
            'secret' => $app_secret,
            'cookie' => true
    ));

    I also tried to just name the two sections in the db:

    appId
    secret

Thank NAME, for their help.

Let NAME know exactly why they deserved these points.

Gift a custom amount of points.