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!!
1 Answer
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
-
thank you, this helps me a lot! I didn't know about this function!– cucuzaCommented Aug 23, 2011 at 19:30
-
No problem, be sure to mark this answer as accepted if it works for you! Commented Aug 23, 2011 at 20:15