如果行數爲0,這應該是直截了當我想回顯消息。以下是我有:
public function getClubComment($id) {
$id = (int) $id;
$row = $this->fetchRow('club_id = ' . $id);
if (!$row) {
echo 'No comments';
}
return $row->toArray();
var_dump($row);
}
如果行數爲0,這應該是直截了當我想回顯消息。以下是我有:
public function getClubComment($id) {
$id = (int) $id;
$row = $this->fetchRow('club_id = ' . $id);
if (!$row) {
echo 'No comments';
}
return $row->toArray();
var_dump($row);
}
也許你可以試試:
//not sure if this will work as I don't do this kind of request anymore
public function getClubComment($id) {
$id = (int) $id;
$row = $this->fetchRow('club_id = ?', $id);
if (!$row) {echo 'No comments';}
return $row->toArray();
var_dump($row);
}
我想你會更快樂做這樣的事情,最需要猜測的工作了。
public function getClubComment($id) {
$id = (int) $id;
//create instance of Zend_Db_Select object
$select = $this select();
$select->where('club_id = ?', $id);
//fetchRow using Zend_Db_Select object
$row = $this->fetchRow($select);
//fetchRow() returns NULL so may as well test for that.
if ($row === NULL) {
throw new Zend_Db_Table_Exception();
}
return $row->toArray();
var_dump($row);
}
Zend_Db_Select是在模型中使用,因爲它通常需要正確引用值的關心和它很容易建立與任何SQL一個相當複雜的SQL查詢非常有用。在這個例子中,我對select()的每個部分都使用了不連續的線條,但是我可以很容易地將它們串在一起。我個人喜歡將每條線分開,以便輕鬆更換或排除故障。
'fetchRow'應,如果沒有結果返回null,什麼'var_dump($ row)'show?在附註中,從DbTable /數據映射器回顯並不是一個好主意。將空結果返回給應用程序以決定要執行的操作。 – drew010
var_dump($ row);什麼也沒有顯示..好的,謝謝 – Rex89
至少,它應該輸出'NULL' - var_dump永遠不會產生任何輸出。你的整個頁面是空白的嗎?檢查服務器error_log文件以獲取可能的解釋。 – drew010