views:

50

answers:

1

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

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

A: 

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.

Gipetto
I'm developing an event calendar - so I will be needing my own tables :) And I don't feel it's 'business best practice' to use option og meta tables for storing custom data from plugins. Maybe if it's an simple plugin with little data.
Steven