0
votes

I want to create a user on both of my sites having different databases. On my first site I code as:-

$newdb = new wpdb('XYZ', 'MXCTv#@', 'XYZ', 'DB URL');
$newdb->show_errors();
$usermain = $newdb->get_results("SELECT * FROM wp_users");          

Is it possible to use wp_create_user( $username, $password, $email ) function for the new Database Object.

Thanks in Advance.

2
Look inside that function, set the global variable, call that function, restore the previous global variable. user create transaction with the new database object done. consider such code fragile, the database class might become subject to change with the next wordpress release (and I'm pretty sure some of the Worpdress developers might fall over their ignorance then). - hakre
Will you illustrate It. Please - Sujeet Kumar
Sure I'm happy to help you. We can do Wordpress consulting so that you can match your customers needs. - hakre

2 Answers

2
votes

If you want to share users between two sites, look into setting up a custom user table, alongside two different DB prefixes for each site:

http://codegarage.com/blog/2009/04/using-a-custom-user-table-share-users-between-two-wordpress-installs/

Alternatively, you can enable WP MultiSite with domain mapping:

http://codex.wordpress.org/Create_A_Network

http://ottopress.com/2010/wordpress-3-0-multisite-domain-mapping-tutorial/

1
votes

You can use MYSQL Query like

$newdb = new wpdb('XYZ', 'MXCTv#@', 'XYZ', 'DB URL');
$newdb->show_errors();
$usermain = $newdb->query("INSERT INTO `databasename`.`wp_users` (`ID`, `user_login`, `user_pass`, `user_nicename`, `user_email`, `user_url`, `user_registered`, `user_activation_key`, `user_status`, `display_name`) VALUES ('4', 'demo', MD5('demo'), 'Syed Balkhi', '[email protected]', 'http://www.wpbeginner.com/', '2011-06-07 00:00:00', '', '0', 'Syed Balkhi');");