我在Codeigniter中遇到了一個奇怪的問題。我運行一個查詢,更新了行:更新查詢沒有更新相應的行
function set_counter($key, $value){
echo "$key : $value => ";
$this->db->query("UPDATE counter SET counter.`value` = ? WHERE counter.`key` = ?", array($value, $key));
return $this->db->affected_rows();
}
基準測試顯示,這個函數被調用和查詢不運行:
UPDATE counter SET counter.`value` = 1 WHERE counter.`key` = 'left_banner_start_id'
該函數返回「1」,這意味着1行得到更新。
但在實際的行不在數據庫得到更新,value
列始終「0」
任何解決什麼,我做錯了什麼?
編輯:
的問題變得更加古怪,當我退出()我的函數,該行實際上得到更新,否則它不會:
function set_counter($key, $value){
echo "$key : $value - ";
$this->db->query("UPDATE counter SET counter.`value` = ? WHERE counter.`key` = ?", array($value, $key));
//print_r($this->db->affected_rows());
exit();
}
編輯:
好吧,如果我在system/core/Output.php中退出()執行,它就可以工作:
// --------------------------------------------------------------------
// Does the controller contain a function named _output()?
// If so send the output there. Otherwise, echo it.
if (method_exists($CI, '_output'))
{
$CI->_output($output);
}
else
{
exit();
echo $output; // Send it to the browser!
}
,但如果我退出()呼應$輸出後還不行:
// --------------------------------------------------------------------
// Does the controller contain a function named _output()?
// If so send the output there. Otherwise, echo it.
if (method_exists($CI, '_output'))
{
$CI->_output($output);
}
else
{
echo $output; // Send it to the browser!
exit();
}
編輯:
我認爲有這條線這是防止它:
<img src="<?php echo base_url().$recent_ad['photo_thumb']; ?>" width="28" height="27" />
這個在另一個視圖:
<img src="<?php echo base_url().$featured_agent['photo_medium']; ?>" width="84" height="84" />
這裏photo_thumb和photo_medium是數據庫中另一個表中的列,它們具有空值。我填充了列,現在它工作正常。
但是爲什麼?是什麼原因?
它是否在函數中打印正確的值? –
是的。一切安好。即使codeigniter顯示查詢運行沒有錯誤,並顯示1行已在db中更新。但實際上沒有更新。 – younis
我認爲根據echo「$ key:$ value =>」;不打印價值 –