Currently, some projects have been developed, and local testing is normal, but it won't work if you put them 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 to mysql locally... currently, some projects have been developed, and local testing is normal, but it won't work if you put them 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 three connectionsmysql
..
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;}
Becausephp
The version is too old to be usedPDO
Access the custom port, and give up.
mysql
Method and
mysqli
Method
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);
The following error is prompted for both methods:
Can't connect to MySQL server on 'cins.swpu.edu.cn' (13)
Obviously, the custom port of the server is not connected, but the custom port is specified during the call. I don't know why.
Reply content:
Currently, some projects have been developed, and local testing is normal, but it won't work if you put them 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 three connectionsmysql
..
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;}
Becausephp
The version is too old to be usedPDO
Access the custom port, and give up.
mysql
Method and
mysqli
Method
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);
The following error is prompted for both methods:
Can't connect to MySQL server on 'cins.swpu.edu.cn' (13)
Obviously, the custom port of the server is not connected, but the custom port is specified during the call. I don't know why.
Enable remote access first for mysql on the server.
We recommend that you first use mysqlworkbench to test and then click OK to run the server program.
1. Check whether the permission is available. Based on the information found on the Internet, the error mysql 13 indicates that you have the write permission.
2. Is mysql listening on a custom port?
3. Is the mysql server configured with remote connection?
According to the Subject description, it is similar that mysql does not enable external connections,
Telnet cins.swpu.edu.cn port number. Try it and see what feedback you have. Or you can directly view your user information in the mysql user table on the server.