即使记录正确插入我仍然得到此错误,无法找到问题所在
INSERT INTO的错误都来了,但是当我检查DB记录是否存在且其正确时如何处理此错误?
这是我的代码和转储
$order_id = $this->db->getLastId();
if ($data['options'] != '') {
foreach ($data['options'] as $filter => $option) {
$check = $this->db->query("SELECT
oc_product_option.option_id,
oc_option.type,
oc_option_description.name,
oc_product_option_value.option_value_id,
oc_option_value_description.name AS option_name
FROM oc_product_option
LEFT JOIN oc_option ON (oc_product_option.option_id = oc_option.option_id)
LEFT JOIN oc_option_description ON (oc_product_option.option_id = oc_option_description.option_id)
LEFT JOIN oc_product_option_value ON (oc_product_option_value.product_option_value_id = '" . (int)$option . "')
LEFT JOIN oc_option_value_description ON (oc_option_value_description.option_value_id = oc_product_option_value.option_value_id)
WHERE oc_product_option.product_option_id = '" . (int)$filter . "'
AND oc_product_option.product_id = '" . (int)$data['product_id'] . "'");
foreach ($check->rows as $option_type) {
if ($option_type['type'] == 'custom') {
$this->db->query("INSERT INTO " . DB_PREFIX . "fast_order_option SET order_id = '" . (int)$order_id . "', order_product_id = '" . (int)$data['product_id'] . "', product_option_id = '" . (int)$filter . "', name = '" . $this->db->escape($option_type['name']) . "', value = '" . $this->db->escape($option) . "', type = '" . $this->db->escape($option['type']) . "'");
}else {
$this->db->query("INSERT INTO " . DB_PREFIX . "fast_order_option SET order_id = '" . (int)$order_id . "', order_product_id = '" . (int)$data['product_id'] . "', product_option_id = '" . (int)$filter . "', product_option_value_id = '" . $this->db->escape($option) . "', name = '" . $this->db->escape($option_type['name']) . "', value = '" . $this->db->escape($option_type['option_name']) . "', type = '" . $this->db->escape($option['type']) . "'");
}
}
}
}
$数据[ '选项']
Array
(
[1330] => 1853
[1181] => 2
[1182] => 1
[1179] => 1660
)
$检查
stdClass Object
(
[num_rows] => 1
[row] => Array
(
[option_id] => 16
[type] => select
[name] => Двулицев Размер
[option_value_id] => 56
[option_name] => 300/100
)
[rows] => Array
(
[0] => Array
(
[option_id] => 16
[type] => select
[name] => Двулицев Размер
[option_value_id] => 56
[option_name] => 300/100
)
)
)
type = '" . $this->db->escape($option['type']) . "'");
}
$option['type']
最后应该有$option_type['type']
- $option
来自你的外部foreach循环,并且此时包含来自$data['options']
的一个整数。