我用下面的代碼:奇怪PDO行爲
try {
$this->conn = new PDO("mysql:host=" . DB_HOST . ";dbname=" . DB_NAME, DB_USERNAME, DB_PASSWORD);
$this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e)
{
echo $e->getMessage();
}
try {
$stmt = $this->conn->prepare("SELECT id, name FROM images");
if ($stmt->execute()) {
if ($stmt->rowCount() > 0)
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
else
return NULL;
}
catch(PDOException $e)
{
return $e->getMessage();
}
的代碼完美的作品,但是當我編輯查詢:
$stmt = $this->conn->prepare("SELECT id, name, description FROM images");
我得到一個空的結果。
顯然說明字段存在。很顯然,我使用PHPMyAdmin測試了這個新查詢。
我發現:
if ($stmt->rowCount() > 0)
是TRUE,我也嘗試將fetclAll更改爲FETCH_BOTH。
你有什麼建議嗎?
編輯:好的,我發現這個問題:
在一個記錄,列描述有一個「E」。如果我刪除了「è」,那麼所有的都是完美的。爲什麼會這樣呢?
你看過你的錯誤日誌嗎?錯誤日誌說什麼? – Michael
我在哪裏可以找到日誌文件? – helloimyourmind
PHP最簡單的方法是在頁面頂部添加'error_reporting(-1);'行,直接在打開php標籤<?php後。那麼如果PHP中有任何錯誤或查詢數據庫時,它會顯示錯誤。 – Michael