Php cannot identify the port number when connecting to mysql

Source: Internet
Author: User
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..

PDOMethod

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;}

BecausephpThe version is too old to be usedPDOAccess the custom port, and give up.

mysqlMethod and mysqliMethod

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..

PDOMethod

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;}

BecausephpThe version is too old to be usedPDOAccess the custom port, and give up.

mysqlMethod and mysqliMethod

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.