Connect forms in WP to external database

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

Leave a Comment