简体   繁体   English

Codeigniter如何解决MySql Query语法中的错误?

[英]How to solve this error in MySql Query syntax in codeigniter?

This is The Error I am getting.. 这是我得到的错误。

You have an error in your SQL syntax; 您的SQL语法有误; check the manual that corresponds to your MySQL server version for the right syntax to use near ' Sensor = 'sklfj', Lens = 'lkjsdf', IR = 'lkjdsf', Audio = 'kjlasf', `WDR' at line 1 检查与MySQL服务器版本相对应的手册,以在第1行的' Sensor ='sklfj', Lens ='lkjsdf', IR ='lkjdsf', Audio ='kjlasf','WDR'附近使用正确的语法

UPDATE `hdtvicameras_spec`
SET `Resolution` = 'd',
 `Image` `Sensor` = 'sklfj',
 `Lens` = 'lkjsdf',
 `IR` = 'lkjdsf',
 `Audio` = 'kjlasf',
 `WDR` = 'lkjsf1',
 `ICR` = 'klasjf',
 `IP` `Rating` = 'lkjsdf',
 `Zoom` = 'ljs'
WHERE
    `product_id` = '46'

Product_model.php Product_model.php

$this->db->where('product_id', $product_id);
$this->db->update($tbname, $spec_array);

After var_dump($spec_array) this is what I get var_dump($spec_array)这就是我得到的

array(10) { 
    ["Resolution"]=> string(5) "first" 
    ["Image Sensor"]=> string(6) "second" 
    ["Lens"]=> string(6) "third " 
    ["IR"]=> string(6) "fourth" 
    ["Audio"]=> string(6) "fifthe" 
    ["WDR"]=> string(6) "sisxth" 
    ["ICR"]=> string(5) "seven" 
    ["IP Rating"]=> string(5) "eight" 
    ["Zoom"]=> string(4) "nine" 
    ["SD Card"]=> string(3) "ten" 
}

All those key values in array are fetched from database which is specification names of any product. 数组中所有这些键值都是从数据库中获取的,该数据库是任何产品的规范名称。

looks like there is some error with space in key name. 密钥名称中的空格似乎有一些错误。 Can anybody help me solve this? 有人可以帮我解决这个问题吗?

use query like this and check: 使用这样的查询并检查:

UPDATE `hdtvicameras_spec`
SET `Resolution` = 'd',
 `Image Sensor` = 'sklfj',
 `Lens` = 'lkjsdf',
 `IR` = 'lkjdsf',
 `Audio` = 'kjlasf',
 `WDR` = 'lkjsf1',
 `ICR` = 'klasjf',
 `IP Rating` = 'lkjsdf',
 `Zoom` = 'ljs'
WHERE `product_id` = '46'

Since you added quotes, for fields names having more then 1 word, its showing error. 由于您添加了引号,对于名称超过1个字词的字段名称,其显示错误。

I think you have error here: 我认为您在这里有错误:

 `Image` `Sensor` = 'sklfj', 

After image you didn't give the value to it. 映像之后,您没有赋予它任何价值。

Since Image Sensor is a column with space in it, therefore you are getting an error. 由于图像传感器是一列带有空格的列,因此会出现错误。 CI is adding ` to every field with a space. CI会将`添加到每个带有空格的字段中。 It is not a good practice to use a space in your columns in MySQL. 在MySQL的列中使用空格不是一个好习惯。

In order to solve this problem, either you should remove space or write a query in below mentioned form and pass it in $this->db->query() . 为了解决此问题,您应该删除空间或以下述形式编写查询,然后将其传递给$this->db->query()

UPDATE `hdtvicameras_spec` 
SET `Resolution` = 'd', `Image Sensor` = 'sklfj', `Lens` = 'lkjsdf', `IR` = 'lkjdsf', `Audio` = 'kjlasf', `WDR` = 'lkjsf1', `ICR` = 'klasjf', `IP Rating` = 'lkjsdf', `Zoom` = 'ljs' 
WHERE `product_id` = '46'

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM