目前的项目开发完了一部分,本地测试正常,但是放到服务器上就不行了。
本地环境:xampp-3.2.2(php-5.6.15, apache-2.4.17)
服务器环境:php-5.3.3
、nginx-1.0.15
、php-fpm
我尝试了3种连接mysql
的方法,在本地无一失败,在服务器无一成功。。
PDO
方法
代码:
1 2 3 4 5 6 7 8 | $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;
}
|
Copier après la connexion
Copier après la connexion
因为服务器的php
版本太旧,无法使用PDO
访问自定义的端口,于是放弃。
mysql
方法和mysqli
方法
代码:
1 2 3 4 | $this ->conn = mysql_connect( $this ->dbHost. ":" . $this ->dbPort, $this ->dbUser, $this ->dbPasword);
$this ->conn=@mysqli_connect( $this ->dbHost, $this ->dbUser, $this ->dbPasswd, $this ->dbName. $this ->dbPort);
|
Copier après la connexion
Copier après la connexion
这个两个方法都会会提示如下错误:
1 | Can 't connect to MySQL server on ' cins.swpu.edu.cn' (13)
|
Copier après la connexion
Copier après la connexion
很明显并没有去连接服务器的自定义端口,但调用时确实指定了自定义端口,不知道这是什么原因
回复内容:
目前的项目开发完了一部分,本地测试正常,但是放到服务器上就不行了。
本地环境:xampp-3.2.2(php-5.6.15, apache-2.4.17)
服务器环境:php-5.3.3
、nginx-1.0.15
、php-fpm
我尝试了3种连接mysql
的方法,在本地无一失败,在服务器无一成功。。
PDO
方法
代码:
1 2 3 4 5 6 7 8 | $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;
}
|
Copier après la connexion
Copier après la connexion
因为服务器的php
版本太旧,无法使用PDO
访问自定义的端口,于是放弃。
mysql
方法和mysqli
方法
代码:
1 2 3 4 | $this ->conn = mysql_connect( $this ->dbHost. ":" . $this ->dbPort, $this ->dbUser, $this ->dbPasword);
$this ->conn=@mysqli_connect( $this ->dbHost, $this ->dbUser, $this ->dbPasswd, $this ->dbName. $this ->dbPort);
|
Copier après la connexion
Copier après la connexion
这个两个方法都会会提示如下错误:
1 | Can 't connect to MySQL server on ' cins.swpu.edu.cn' (13)
|
Copier après la connexion
Copier après la connexion
很明显并没有去连接服务器的自定义端口,但调用时确实指定了自定义端口,不知道这是什么原因
服务器的mysql开启远程访问先。
建议还是先使用mysqlworkbench测试一下,确定ok,再上服务端程序。
1、确定是否权限是有的,根据网上查找的信息:mysql 13 的错误是提示有写权限的问题
2、mysql 是否自定义的端口上进行监听
3、mysql服务器是否配置了可以远程连接
根据题主描述,很像mysql没有开启外连,
telnet cins.swpu.edu.cn 端口号,试一下看看什么反馈。或者你直接在服务器上查看mysql user表你的用户信息。