What is best practice for working with DB in WordPress?

I’m developing a plugin for WordPress, and I need to store some information from a form into a table in the DB.

There are probably lots of pages explaining how to do this, this being one of them:
http://codex.wordpress.org/Function_Reference/wpdb_Class

Read More

But are there any other pages talking about best practice for interacting with th WP DB?

UPDATE
Found a few more pages which could be usefull:
http://wpengineer.com/wordpress-database-functions
http://blue-anvil.com/archives/wordpress-development-techniques-1-running-custom-queries-using-the-wpdb-class

Related posts

Leave a Reply

2 comments

  1. Unless you need to create your own complex table structure I’d suggest using the existing tables for your needs. There’s the options table, user meta table, and post meta table to work with. These all have built in apis for quick access.

    • Options: add_option(), get_option(), update_option(), delete_option()
    • Usermeta: add_user_meta(), get_user_meta(), update_user_meta(), delete_user_meta()
    • Postmeta: add_post_meta(), get_post_meta(), update_post_meta(), delete_post_meta()

    I’ve not found much real need to go outside of these tables (yes, there are exceptions, I’ve done them myself when the data needs are complex) but these meta options all use a text field in the db to store the data, so there’s a lot you can store here if its simple data.

    If your data is simple then consider storing your information in one of these places as individual options or even as serialized arrays.

  2. One of my BIGGEST pet peeves with plug in developers that leverage the WP database is that if/when a given database driven plugin isn’t used anymore, the developer doesn’t think to remove the footprint it made in the database.