The current project has been partially developed, and local testing is normal, but not on the server.
Local Environment:
xampp-3.2.2(php-5.6.15, apache-2.4.17)
Server environment:
php-5.3.3
、
nginx-1.0.15
、
php-fpm
I tried 3 ways to connect mysql
, no one failed locally, no success on the server.
PDO
Method
Code:
$dsn = "mysql:dbname=$db;port=$this->dbPort;host=$this->dbHost;charset=$charset";try { $this->conn = new PDO($dsn, $this->dbUser, $this->dbPasswd); return $this->conn;} catch (PDOException $e) { $this->DealError($e); return false;}
Because the version of the server php
is too old to PDO
access the custom port, it is discarded.
mysql
Methods and mysqli
methods
Code:
//mysql$this->conn = mysql_connect($this->dbHost.":".$this->dbPort, $this->dbUser, $this->dbPasword);//mysqli$this->conn=@mysqli_connect($this->dbHost, $this->dbUser, $this->dbPasswd, $this->dbName. $this->dbPort);
This two method will prompt the following error:
Can't connect to MySQL server on 'cins.swpu.edu.cn' (13)
Obviously there is no custom port to connect to the server, but it does specify a custom port when it is called, and I don't know why.
Reply content:
The current project has been partially developed, and local testing is normal, but not on the server.
Local Environment:xampp-3.2.2(php-5.6.15, apache-2.4.17)
Server environment: php-5.3.3
, nginx-1.0.15
,php-fpm
I tried 3 ways to connect mysql
, no one failed locally, no success on the server.
PDO
Method
Code:
$dsn = "mysql:dbname=$db;port=$this->dbPort;host=$this->dbHost;charset=$charset";try { $this->conn = new PDO($dsn, $this->dbUser, $this->dbPasswd); return $this->conn;} catch (PDOException $e) { $this->DealError($e); return false;}
Because the version of the server php
is too old to PDO
access the custom port, it is discarded.
mysql
Methods and mysqli
methods
Code:
//mysql$this->conn = mysql_connect($this->dbHost.":".$this->dbPort, $this->dbUser, $this->dbPasword);//mysqli$this->conn=@mysqli_connect($this->dbHost, $this->dbUser, $this->dbPasswd, $this->dbName. $this->dbPort);
This two method will prompt the following error:
Can't connect to MySQL server on 'cins.swpu.edu.cn' (13)
Obviously there is no custom port to connect to the server, but it does specify a custom port when it is called, and I don't know why.
Server MySQL to open remote access first.
Recommended or first Use Mysqlworkbench test, OK, and then on the server program.
1, determine whether the permissions are there, according to the information found on the Internet: MySQL 13 error is prompted to write permission issues
2. Whether MySQL is listening on a custom port
3. Whether the MySQL server is configured to connect remotely
According to the main description, much like MySQL does not open the outer connection,
Telnet cins.swpu.edu.cn port number, try to see what feedback. Or you could view the MySQL user table directly on the server.