I have a mySQL database hosted locally using WAMP, I went through all the procedures to access it remotely and seem to have succeeded in that I can put the IP address into my phone, see WAMP and access phpmyAdmin etc.
My issue is that I want to test the database connection using the script below from my website (ultimately I want to use a WP plugin to get info off the DB and then close it).
However I am not fully sure what the parameters would be.
Apache server is on port 80 and mysql is on port 3306. I have setup port forwarding on those ports and tested them using http://www.canyouseeme.org/
Therefore would my host be myIP (using What is myIP) : 80 or 3306.
I have tried both and they fail. Would my user name be root or Root@Host
Like I say ultimately I want to test this, connect to the database and then use the parameters in a WordPress plugin to copy data from my locally hosted DB to my site's db.
Please advise.
Thank you.
<?php
# Fill our vars and run on cli
# $ php -f db-connect-test.php
$dbname = 'name';
$dbuser = 'user';
$dbpass = 'pass';
$dbhost = 'host';
$connect = mysql_connect($dbhost, $dbuser, $dbpass) or die("Unable to Connect to '$dbhost'");
mysql_select_db($dbname) or die("Could not open the db '$dbname'");
$test_query = "SHOW TABLES FROM $dbname";
$result = mysql_query($test_query);
$tblCnt = 0;
while($tbl = mysql_fetch_array($result)) {
$tblCnt++;
#echo $tbl[0]."<br />\n";
}
if (!$tblCnt) {
echo "There are no tables<br />\n";
} else {
echo "There are $tblCnt tables<br />\n";
}