我正在研究codeigniter框架。其中我必须使用特定列编辑db中的行。
我试过下面的代码,但它给了我错误:
发生数据库错误
错误号码: 1054
'字段中的未知列'Vendor_1360622286' list'
UPDATE
vendors
SET vendor_id = Vendor_1360622286, vendor_name = fsd,vendor_address = fds,vendor_phone = fsdf, vendor_email = sdfsdfsd WHEREvendor_id
= 'Vendor_1360622286'文件名: C:/ xampp / htdocs / **** / system / database / DB_driver.php
行号: 691
代码:
$this->db->set('vendor_id', $data['vendor_id'], FALSE);
$this->db->set('vendor_name', $data['vendor_name'], FALSE);
$this->db->set('vendor_address', $data['vendor_address'], FALSE);
$this->db->set('vendor_phone', $data['vendor_phone'], FALSE);
$this->db->set('vendor_email', $data['vendor_email'], FALSE);
$this->db->where('vendor_id', $data['vendor_id']);
$status = $this->db->update('vendors');
Db表(供应商)中的列
`id` int(11) NOT NULL,
`vendor_id` varchar(50) NOT NULL,
`vendor_name` varchar(300) NOT NULL,
`vendor_address` varchar(500) NOT NULL,
`vendor_phone` varchar(100) NOT NULL,
`vendor_email` varchar(100) NOT NULL,
`created_at` varchar(50) NOT NULL
任何想法,为什么它在where子句上给我错误?
答案 0 :(得分:1)
请尝试以下代码:
$update_data=array("vendor_id"=> $data['vendor_id'],"vendor_name"=> $data['vendor_name'],"vendor_address"=> $data['vendor_address'],"vendor_phone"=> $data['vendor_phone'],"vendor_email"=> $data['vendor_email']);
$condi=array("vendor_id"=>$data['vendor_id']);
$this->db->where($condi);
$res=$this->db->update("vendors",$update_data);
if($res)
echo "Recored Updated";
else
echo "Not Updated";
答案 1 :(得分:0)
您将第三个参数传递给set()
FALSE
,因此它不会正确转义字符串值。查询应为UPDATE vendors SET vendor_id = 'Vendor_1360622286', vendor_name = 'fsd', vendor_address = 'fds', vendor_phone = 'fsdf', vendor_email = 'sdfsdfsd' WHERE vendor_id = 'Vendor_1360622286'
。
只需从通话中删除FALSE
参数,您就可以了。
答案 2 :(得分:0)
试试这个:
sklearn
数据数组必须包含您要更改的ID和所有信息。