TP number of bound variables does not match number of tokens

Source: Internet
Author: User
    • PHP Version: PHP 5.4.16

    • thinkphp version: 3.2.3

Directly on the code:

$data:Array(    [area] => aa    [brand] => bb    [color] => cc    [type] => 通勤车    [alerted_police] => 0    [status] => 0    [lost_time] =>     [info] => dd    [email] => email@email.com    [update_time] =>     [timestamp] => 1    [img_info_id] => 201610081621501801716297)

$sql = $ReportLost->fetchsql (True)->add ($data);

INSERT INTO `report_lost` (`area`,`brand`,`color`,`type`,`alerted_police`,`status`,`lost_time`,`info`,`email`,`update_time`) VALUES ('aa','bb','cc','通勤车','0','0',NULL,'dd','email@email.com',NULL)

Next execution $result = $ReportLost->add($data); will cause an error:

ERR: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens

In MySQL, however, the direct execution $sql of the

mysql> INSERT INTO `report_lost` (`area`,`brand`,`color`,`type`,`alerted_police`,`status`,`lost_time`,`info`,`email`,`update_time`) VALUES ('aa','bb','cc','通勤车','0','0',NULL,'dd','email@email.com',NULL);Query OK, 1 row affected (0.02 sec)

is available for insertion.

Data table structure

--Table structure ' report_lost '--create table IF not EXISTS ' report_lost ' (' id ' int (one) not NULL, ' title ' varchar) CHARACTER S ET utf8mb4 default null, ' keyword ' varchar (+) CHARACTER set utf8mb4 DEFAULT null, ' area ' varchar (CHARACTER set UTF)  8MB4 default NULL, ' brand ' varchar (CHARACTER) set utf8mb4 DEFAULT null, ' sub_brand ' varchar CHARACTER set UTF8MB4 DEFAULT null, ' color ' varchar (CHARACTER set UTF8MB4 not NULL, ' type ' varchar () CHARACTER SET utf8mb4 not NULL, ' Alerted_police ' int (4) NOT null default ' 0 ', ' status ' int (4) is not null default ' 0 ', ' info ' text CHARACTER SET utf8mb4, ' Image ' text CHARACTER set UTF8MB4, ' user ' varchar (CHARACTER set UTF8MB4 DEFAULT NULL, ' email ' varchar () CHARACTER Set UTF8MB4 NOT NULL, ' contact ' varchar (CHARACTER set UTF8MB4 DEFAULT NULL, ' descrpition ' text CHARACTER set UTF8MB4 , ' uuid ' varchar (CHARACTER) SET utf8mb4 DEFAULT ' 00000000-0000-0000-0000-000000000000 ', ' lost_time ' timestamp NULL DE FAULT NULL, ' Create_timE ' timestamp not null default Current_timestamp, ' update_time ' timestamp null default NULL) ENGINE=INNODB default CHARSET =UTF8MB4 Collate=utf8mb4_unicode_ci;

The fields in the table are indeed more than those in $data, but the undefined in $data can be null.

Is this the thinkphp limit? Or a PHP limit? What's the solution, do I need to define all the fields required by MySQL in $data?

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.