0

I am trying to connect with another database in WordPress and insert data into a new table. I am creating a new object of wpdb

$newconnection= new wpdb("localhost","username","password","databasename");

and then trying to insert the data:

$newdb->insert('tablename', array('fullname'=> $_REQUEST['fullname'],'email'=> $_REQUEST['email']);

but i am not able to insert the data into new table of the new database.

its showing the error "ERROR ESTABLISHING A DATABASE CONNECTION".

Please try to resolve my query

1

Look at the order of the constructor arguments in the documentation:

string $dbuser, string $dbpassword, string $dbname, string $dbhost

You've got the arguments in the wrong order. Move the host to the end:

$newconnection= new wpdb("username","password","databasename","localhost");
  • No problem. If you could take a moment to mark the answer as accepted I'd appreciate it. – Jacob Peattie May 31 '18 at 8:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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