繁体   English   中英

mysql_error奇怪的行为(始终返回空字符串)

[英]mysql_error strange behavior (return always empty string)

我得到这种奇怪的行为:

假设您有一个仅创建与MySQL的连接并返回连接链接的类。

class Connection {

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

}

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

但!! 如果我将链接创建放置在mysql_querymysql_errnomysql_error的同一类中,那么它们都可以正常工作!

有人遇到过同样的问题吗?

mysql

已弃用,请考虑使用

mysqli

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM