gpt4 book ai didi

php - mysql_error 奇怪的行为(总是返回空字符串)

转载 作者:行者123 更新时间:2023-11-30 23:50:58 24 4
gpt4 key购买 nike

我遇到了这种奇怪的行为:

假设您有一个类,它只创建到 MySQL 的连接并返回连接链接。

class Connection {

private $conn;
public function __construct() {
$this->conn = mysql_connect(.....);
}
public function getConn() {
return $this->conn;
}

}

现在,如果我尝试使用连接链接(当然是实例化连接并使用 $instance->getConn()),我可以使用 mysql_query 中的链接> 函数,但我不能在 mysql_errormysql_errno 中使用它(它们总是分别返回 ''0,即使执行的查询是绝对错误的)。

但是!!如果我将链接创建放在 mysql_querymysql_errnomysql_error 的同一类中,一切都完美无缺!!

有人遇到同样的问题吗?

最佳答案

mysql

已弃用,考虑使用

mysqli

http://www.php.net/manual/en/mysqli.query.php

关于php - mysql_error 奇怪的行为(总是返回空字符串),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11268425/

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