1

I need to connect to a external database on my wordpress site but this database is on a VPS so I have the SSH Hostname, SSH username, SSH password, MySQL HostName on the VPS, MySQL port on the VPS, the Mysql username and the MySQL Password but the wpdb object just ask for the database host, password, table and user so where should be defined the vps authentication information? can I use mslqli extension to achieve the connection ? if so how can I install the extension on wordpress?

1
  • 1
    A couple of questions: 1. Are you trying to connect to a WordPress database on the server? (WP_???) or are you trying to connect to a separate database to run with your plugin. 2. Is this a custom plugin that was written for you or a particular plugin you installed? Commented Dec 30, 2022 at 21:51

1 Answer 1

1

You can create a new wpdb object, and then use that.

global $mydb;
$mydb = new wpdb( $db_user, $db_pass, $db_name, $db_host );

...and then use $mydb as you would the global $wpdb object.

2
  • thanks for the answer, but which will be the $db_user, $db_pass, $db_name, $db_host if i use the ones of the mysql database wont be connected because the vps dont have exposed this to the internet, just the ssh credentials so this won't work
    – TTT2
    Commented Dec 28, 2022 at 4:36
  • 1
    You'd need the MySQL username and password. If you can't connect to the database over the internet, then WordPress can't connect to it (unless it's on the same VPS, I suppose).
    – Pat J
    Commented Dec 28, 2022 at 5:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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