我无法理解这个......
控制器:
public function update()
{
$string = 'xml/gzip';
$xml = simplexml_load_file("compress.zlib://$string");
foreach ($xml->merchant as $merchant) {
$merchant_name = $merchant['name'];
$merchant_id = $merchant['id'];
$data1 = array(
'merchant_id' => $merchant_id,
'merchant_name' => $merchant_name
);
$this->load->model('Administration_model');
$this->Administration_model->insert_merchants($data1);
}
}
型号:
public function insert_merchants($data1)
{
$this->db->insert('merchants', $data1);
}
我的控制器中的
foreach
循环正在运行来自 xml 电子表格的数据,正如错误所示 - 值“911”和“website.com”应该是插入的值...那么为什么它确定“website.com”? com”作为“字段列表”?
错误:
A Database Error Occurred
Error Number: 1054
Unknown column 'website.com' in 'field list'
INSERT INTO `merchants` (`merchant_id`, `merchant_name`) VALUES (911, website.com)
这与
merchant_id
是主列并且这在技术上是重复条目这一事实有什么关系吗...如果是这样,关于如何添加“ON DUPLICATE KEY...”功能的任何提示?
您需要引用字符串,否则它认为您引用的是列名称。
INSERT INTO `merchants` (`merchant_id`, `merchant_name`) VALUES (911, 'website.com')
您的代码看起来没有任何问题。我建议升级到 CodeIgniter 的最新版本(当前为 3.1.5),然后重新运行您的代码。
$data = array(
'merchant_id' => 911,
'merchant_name' => 'website.com',
);
$this->db->insert('merchants', $data);
如果您仍然遇到问题,请尝试硬编码一个值并让我们知道会发生什么。
对于重复密钥问题,CodeIgniter 3.1.5 有一个替换功能,可以更新重复密钥。 请记住使用此功能的性能损失,对于大型导入,这可能会非常慢。对于大型数据集,请考虑对查询进行批处理。
$data = array(
'merchant_id' => 911,
'merchant_name' => 'website.com',
);
$this->db->replace('merchants', $data);
数据库发生错误 错误编号:1054
“字段列表”中存在未知列“图像”
插入
user
(name
、email
、image
、password
、role_id
、is_active
、date_created
) 值 ('Rioho Danar sakti',编辑] ', 'default.jpg', '$2y$10$ZKZPow.V1o0oUfCPOYetkeD6eY0exFdQ4doRbevi4EiO/lxSWf7WK', 2, 1, 1719971888)
文件名:C:/xampp/htdocs/db_pasien/system/database/DB_driver.php线路号码:691