我怎么能修复这个mysql错误没有1064错误?

时间:2018-04-18 06:08:05

标签: php codeigniter

插入数据时收到此错误。

  

错误号码:1064

You have an error in your SQL syntax; check the manual that corresponds to 
your MariaDB server version for the right syntax to use near '( [website] => 
[business_contact] => [business_landline] => ' at line 2

以下是查询。

     INSERT INTO `sp_business_details` (
        Array (
            [website] =>
            [business_contact] =>
            [business_landline] =>
            [state] => 1
            [state_name]=> Maharashtra
            [district] => 1
            [district_name] => Ahemadnagar
            [city] => 1
            [city_name] => Akole
            [pincode] => 425001
            [business_type] => 2
            [business_subtype] => 2
            [business_description] => A
            [address] => A
            [working_hrs_start] => 11:18 AM
            [working_hrs_end] => 11:18 AM
            [closed_day] => Sunday
            [registered_from] => 1
            [created_date] =>2018-04-18
        )
    ) VALUES ('');

我正在使用codeigniter $this->db->insert功能。并将数据数组传递给此函数

$q_businessdetails=$this->db->insert('sp_business_details',$sp_business_data);


var_dump($sp_business_data);o/p
string(686) "Array
(
[wbuser_id] => 153
[shop_name] => Moraya Computer Services
[shop_number] => 10
[website] => http://www.google.com
[business_contact] => 9403384505
[business_landline] => 2260676
[state] => 1
[state_name] => Maharashtra
[district] => 1
[district_name] => Ahemadnagar
[city] => 1
[city_name] => Akole
[pincode] => 425001
[business_type] => 1
[business_subtype] => 1
[business_description] => A
[address] => Adarsh Nagar Jalgaon
[working_hrs_start] => 11:18 AM
[working_hrs_end] => 11:18 AM
[closed_day] => Sunday
[registered_from] => 1
[created_date] => 2018-04-18

) "

2 个答案:

答案 0 :(得分:0)

错误#1064意味着MySQL无法理解您的命令。解决它:

阅读错误消息。它告诉你MySQL命令的确切位置。

查看手册。通过与MySQL在此时的预期进行比较,问题通常很明显。

检查保留字。如果对象标识符发生错误,请检查它是否为保留字(如果是,请确保它已正确引用)。

有关详细信息,请参阅此link

答案 1 :(得分:0)

您发布的查询:

 INSERT INTO `sp_business_details` (
    Array (
        [website] =>
        [business_contact] =>
        [business_landline] =>

根本无效。 $this->db->insert('table', $array);期望数组作为第二个参数,当您为其提供由var_dump表示的字符串时。我不确定你是如何编写数组的,但正确的语法是:

$somearray = array('key' => 'value', 'key2' => 'value2');

它看起来好像你提供print_r()作为第二个参数。这只是一种可视化数组的方式,而不是一种适当的语法。