PHP connection MySQL does not recognize the port number

Source: Internet
Author: User
Tags dsn
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.3nginx-1.0.15php-fpm

I tried 3 ways to connect mysql , no one failed locally, no success on the server.

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

Because the version of the server php is too old to PDO access the custom port, it is discarded.

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

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

Because the version of the server php is too old to PDO access the custom port, it is discarded.

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

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