$cuntRs = $this->db->query("SELECT count(*) as cunt from " . DB_PREFIX . "vendhq_product");
if($cuntRs->row["cunt"]==0) {
foreach ($json["products"] as $dept){
echo "<strong> Product ". $i++ ."</strong><br/>";
$passval=$i;
echo $dept["name"]."<br/>"; echo $dept["id"]."<br/>";
$this->addVendHQproducts($dept,$passval);
}
}
function addVendHQproducts($dept,$pro_id) {
$this->db->query("INSERT INTO " . DB_PREFIX . "vendhq_product SET id = '" . $pro_id . "', vendhq_id = '" . $dept["id"]. "', name = '" . $dept["name"]. "', description = '" . $dept["description"]. "',image = '" . $dept["image"] . "', image_large = '" . $dept["image"]. "', tag = '" . $dept["tags"]. "', price = '" . $dept["price"] . "', supplier_name = '" . $dept["supplier_name"] ."'");
}
&GT?; 的输出:
Product 0
.........1
...........3..
Fatal error: Uncaught exception 'ErrorException' with message 'Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's server</p>',image = 'http://mohamedkaremullasha.vendhq.com/images/placeholder/' at line 1<br />Error No: 1064<br />INSERT INTO oc_vendhq_product SET id = '5', vendhq_id = 'bbeef777-9ac0-11e3-a0f5-b8ca3a64f8f4', name = 'TradeSender', description = '<p>trade sender iphone and ipod application to receive instant updates from ambibroker's server</p>',image = 'http://mohamedkaremullasha.vendhq.com/images/placeholder/product/no-image-white-thumb.png', image_large = 'http://mohamedkaremullasha.vendhq.com/images/placeholder/product/no-image-white-thumb.png', tag = 'share market, share updates', price = '100', supplier_name = 'Hibrise Tech -Suppliers'' in /Applications/XAMPP/xamppfiles/htdocs/mks/opencart-1.5.6.1/upload/system/database/mysqli.php:40 Stack trace: #0 /Applications/XAMPP/xamppfiles/htdocs/mks/opencart-1.5.6.1/uplo in
第40行的/Applications/XAMPP/xamppfiles/htdocs/mks/opencart-1.5.6.1/upload/system/database/mysqli.php
//请告诉我如何处理php中的错误异常
答案 0 :(得分:2)
更改您的INSERT
查询,如下所示:
$this->db->query("INSERT INTO " . DB_PREFIX . "vendhq_product SET id = '" .(int)$pro_id . "', vendhq_id = '" . (int)$dept["id"]. "', name = '" . $this->db->escape($dept["name"]). "', description = '" . $this->db->escape($dept["description"]). "',image = '" . $this->db->escape($dept["image"]) . "', image_large = '" . $this->db->escape($dept["image"]). "', tag = '" . $this->db->escape($dept["tags"]). "', price = '" . $dept["price"] . "', supplier_name = '" . $this->db->escape($dept["supplier_name"]) ."'");
度过美好的一天!!
答案 1 :(得分:1)
您需要确保正确转义内容
'trade sender iphone and ipod application to receive instant updates from ambibroker's server'
由于'
中的ambibroker's
,会导致问题
使用mysqli_real_escape_string
或mysql_real_escape_string
php函数
答案 2 :(得分:0)
“来自ambibroker's”的描述中有一条单引号会扰乱查询。
答案 3 :(得分:0)
正如其他一个值所指出的那样,它的值为'
。所以你需要在插入之前将其转义
将值插入数据库时,最好使用mysqli_real_escape_string
或mysql_real_escape_string
。因此,将此函数用于您用于密集到DB
$this->db->query("INSERT INTO " . DB_PREFIX . "vendhq_product SET id = '" . mysql_real_escape_string($pro_id) . "', vendhq_id = '" . mysql_real_escape_string($dept["id"]). "', name = '" . mysql_real_escape_string($dept["name"]). "', description = '" .mysql_real_escape_string( $dept["description"]). "',image = '" . mysql_real_escape_string($dept["image"]) . "', image_large = '" . mysql_real_escape_string($dept["image"]). "', tag = '" . mysql_real_escape_string($dept["tags"]). "', price = '" . mysql_real_escape_string($dept["price"] ). "', supplier_name = '" . mysql_real_escape_string($dept["supplier_name"]) ."'"); }