gpt4 book ai didi

php - 注意 : . .. Unknown on line 0 - How to find correct line, it's NOT "line 0"

转载 作者:可可西里 更新时间:2023-11-01 13:31:00 27 4
gpt4 key购买 nike

编辑:添加了 PDO 调用。

这是实际的错误:

Notice: Object of class PDOStatement could not be converted to int in Unknown on line 0

我通常如何找出哪一行是错误/通知的正确行,因为它是NOT第 0 行

我尝试使用 register_tick_function 回显 file:line,但这不起作用,因为通知总是在我的总输出结束时输出。

我正在寻找一种通用的调试方法,因为我在该对象的类中找不到任何错误。

// PHP PDO Standard
$db_server = 'mysql:host='.$this->db_host.';dbname='.$this->db_dbase;
try {
$this->db_connection = new PDO($db_server, $this->db_user, $this->db_pass);
$pdo_set = $this->db_connection->setAttribute(PDO::ATTR_EMULATE_PREPARES, FALSE);
$pdo_set = $this->db_connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$pdo_set = $this->db_connection->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
//DebugPrint($pdo_set, '$pdo_set');
} catch (PDOException $e) {
//print 'Error!: '.$e->getMessage().'<br/>';
die();
}

最佳答案

最后,我找到了我自己的问题的答案:

// doing PDO-sql, inserting session data, I ran into my problem.
$this->db_connection = new PDO(...);
$sql_query = "INSERT INTO ".$this->session_db_table." (...) VALUES (...)";
$sql_result = $this->db_connection->query($sql_query);

// This is the line (ideally named "0") from the notice:
return $sql_result;

return $sql_result 抛出这个通知:

“注意:类 PDOStatement 的对象无法在第 0 行的 Unknown 中转换为 int”

$sql_result 是一个对象;预期的返回格式似乎是 boolean

所以我删除了这个return,通知现在消失了。

关于php - 注意 : . .. Unknown on line 0 - How to find correct line, it's NOT "line 0",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9076899/

27 4 0
文章推荐: html - 当主
包装器中有第二个