Reputation: 2914
I'm a beginner and I'm trying to connect remotely to my MySQL database server, but still don't succeed.
I have a dedicated server and my provider doesn't want to help me.
-CentOS 6
with Parallels Plesk 12 (64-bit)
-
I'm accessing my server trough Parallels Plesk. I set up a administrator and database user with "allow remote connection from any host".
I'm able to access my server with FTP
and the MySQL
database server locally, but not from my computer.
I have this error displaying when trying to connect with php:
Warning: PDO::__construct(): MySQL server has gone away in /Users/X/Sites/connexionBDD.php on line 31
Here is the way I connect:
define("DB_SERVER","mywebsite.com:8443");
define("DB_NAME","databasName");
define("DB_USER","MyUser");
define("DB_PWD","MyPassword");
try {
//line 31
$bdd = new PDO('mysql:host='.DB_SERVER.';dbname='.DB_NAME, DB_USER, DB_PWD);
}
catch (Exception $e) {
die($e->getMessage());
}
echo 'You made it';
For DB_SERVER
, if using IP
address, do I need to give V4 + port
?
Upvotes: 1
Views: 407
Reputation: 119186
The host and port should not be specified in the same variable, split them up and define your DSN like below. Additionally, check the port is the correct one, MySQL by default uses port 3306.
define("DB_SERVER","mywebsite.com");
define("DB_PORT","8443");
define("DB_NAME","databasName");
define("DB_USER","MyUser");
define("DB_PWD","MyPassword");
try {
//line 31
$bdd = new PDO('mysql:host='.DB_SERVER.';port='.DB_PORT.';dbname='.DB_NAME, DB_USER, DB_PWD);
}
catch (Exception $e) {
die($e->getMessage());
}
echo 'You made it';
Upvotes: 1