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?
-
1A 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?– John SwaringenCommented Dec 30, 2022 at 21:51
Add a comment
|
1 Answer
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.
-
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– TTT2Commented Dec 28, 2022 at 4:36 -
1You'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 JCommented Dec 28, 2022 at 5:13