我完全難住了。這裏是我的PHP(笨)代碼:mysql查詢沒有從應用程序內部正確運行
function mod()
{
$uid = $this->session->userdata('uid');
$pid = $this->input->post('pid');
if ($this->_verify($uid,$pid))
{
$name = $this->input->post('name');
$price = $this->input->post('price');
$curr = $this->input->post('curr');
$url = $this->input->post('url');
$query = $this->db->query("UPDATE items SET
name=".$this->db->escape($name).",
price=".$this->db->escape($price).",
currency=".$this->db->escape($curr),",
url=".$this->db->escape($url)."
WHERE pid=".$this->db->escape($pid)." LIMIT 1");
}
header('location: '.$this->session->userdata('current'));
}
這段代碼的目的是修改在「項目」表中的一行的屬性(名稱,價格,幣種,URL)(priary關鍵是pid
) 。但是,由於某種原因,允許此函數運行一次後,將修改表中所有條目的名稱,價格,貨幣和網址,而不管它們的pid和我在查詢結尾處添加的LIMIT 1事物。就好像查詢的最後一行被完全忽略。
彷彿這不是很奇怪,我換成「$query = $this->db->query(
」與「echo
」看到SQL查詢正在運行,並且它多輸出的查詢像我期望:
UPDATE items
SET name = 'newname',
price = 'newprice',
currency = 'newcurrency',
url = 'newurl'
WHERE pid = '10'
LIMIT 1
複製 - 將其存入MySQL窗口的行爲與我想要的完全一樣:它使用選定的pid修改該行。
這是怎麼回事?
我投入了限制1,看看它是否會有所作爲。它繼續修改所有行,儘管它讓我更困惑。 ( – Mala 2010-03-27 23:27:12