gpt4 book ai didi

PHP - 指定端口设置的 MySQL 连接

转载 作者:行者123 更新时间:2023-11-29 12:34:14 30 4
gpt4 key购买 nike

我有自己的 DB.php,在我将 MySQL 端口更改为除默认值 3306 之外的其他端口之前,它可以正常工作。现在无法连接;我在端口更改后配置了 DB.php,如下所示:

class DB {
// server
private $host = "192.168.1.15";
private $uname = "user";
private $pw = "iamuser";
private $dbname = "matlab";
private $con = null;
private $port = "669";

public function __construct() {
$this->con = mysql_connect($this->host,$this->port, $this->uname, $this->pw);
if (!$this->con) {
$this->db_error("Cannot connect to DBMS");
}
mysql_query("SET NAMES 'latin5'", $this->con);
mysql_query("SET CHARACTER SET 'latin5'", $this->con);
mysql_query("SET COLLATION_CONNECTION = 'latin5_turkish_ci'", $this->con);
mysql_select_db($this->dbname, $this->con) or db_error("Can not connect to Database");
}

谁能告诉我如何让它再次与端口号 669 一起工作?谢谢。

最佳答案

修复:

您向mysql_connect函数传递了错误的参数,port不是一个单独的参数。第一个参数接受 [hostname:port] 形式的值。所以应该是:

mysql_connect($this->host.':'.$this->port, $this->uname, $this->pw);

引用:

http://php.net/manual/en/function.mysql-connect.php

附注

注意:MySQL 库已弃用,请使用 MySQLiPDO相反

关于PHP - 指定端口设置的 MySQL 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27035670/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com