Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I want to use Wordpress for an existing site (coded in PHP). It has some forms (for member subscription, user can update their data etc.) which are connected directly to an existing database. I don't want to touch or change the DB, because it's a huge member database. So my problem now is - how can I use a contact form within wordpress which sends the data automatically to this existing database? Thanks for your help!!

share|improve this question

1 Answer 1

You can easily connect to another DB using the wpdb class: $external_users_db = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST); (substituting in your applicable values, of course).

From there you can use the get_results, insert, update, and query methods (among others) to do what you need to do, e.g. $external_users_db->get_results( "SELECT ID, username FROM users" );.

The Codex has pretty thorough information: http://codex.wordpress.org/Class_Reference/wpdb

share|improve this answer
thank you, this helps me a lot! I didn't know about this function! –  cucuza Aug 23 '11 at 19:30
No problem, be sure to mark this answer as accepted if it works for you! –  helenhousandi Aug 23 '11 at 20:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.