php - mysql无法插入8列的表

标签 php mysql

我试图在 8 列的表中插入数据,但它不起作用。我正在使用 mysql 版本 5.7.11 。然而,当我将其减少到 6 列时,它会起作用,7 列也无法工作。

请在下面找到表格及其 php 代码

  1. 6 列 mysql/php

1.1 PHP

$res=$pdo->prepare('INSERT INTO '.$table.'(title,description,image,city,price) VALUES(:titl,:decri,:img,:cty,:prce)');

$res->bindParam(':titl',$title);
     $res->bindParam(':decri',$decri);
     $res->bindParam(':img',$item_img);
     $res->bindParam(':cty',$city);
     $res->bindParam(':prce',$price);

1.2 mysql

 CREATE TABLE `mobiles` 
 (`id` int(11) NOT NULL,
 `title` varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
 `description` varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
`image` longblob NOT NULL,
`city` varchar(20) NOT NULL,
`price` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  • 8 列表格
  • 2.1 mysql代码

      CREATE TABLE `mobiles` (
     `id` int(11) NOT NULL,
    `title` varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
    `description` varchar(100) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT   NULL,
     `image` longblob NOT NULL,
    `city` varchar(20) NOT NULL,
    `price` int(11) NOT NULL,
    `user_id` int(10) NOT NULL,
    `date` datetime NOT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    

    2.2 PHP代码

    $res=$pdo->prepare('INSERT INTO'.$table.'(title,description,image,city,price,user_id,date)    VALUES(:titl,:decri,:img,:cty,:prce,:user_id,:dte)');
         $res->bindParam(':titl',$title);
         $res->bindParam(':decri',$decri);
         $res->bindParam(':img',$item_img);
         $res->bindParam(':cty',$city);
         $res->bindParam(':prce',$price);
         $res->bindParam(':user_id',$user_id);
         $res->bindParam(':dte',$date);
    

    我在之后立即执行,六列有效,但八列有效

    为什么mysql不能插入超过6列,而列数限制可以达到255。

    我的代码有问题吗?我回应了所有条目,它们都工作正常。

    请问有什么帮助吗?

    最佳答案

    第二个查询中的 'INSERT INTO'$table 之间没有空格,因此查询因语法错误而失败。

    关于php - mysql无法插入8列的表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38159963/

    相关文章:

    mysql - 如何将 SQL where LENGTH() 条件转换为 xPDO?

    PHP 用 mysql 列的总和填充数组

    php - 这是否正确使用 PDO 和准备好的语句来实现安全登录?

    php - 在 mysql 中使用 2 order by 子句对表获取进行排序

    mysql - 如何将 Coldfusion 连接到 MySQL 数据库

    mysql - 'Age' 中的未知列 'field list'

    php - Laravel php 规范列表表

    php - 使用 mysql 将行连接在一起

    php - 我想将两种形式插入数据库,一种用于创建表,另一种用于插入数据,但它不插入数据库

    php - Windows:在部署到 Amazon Beanstalk 之前设置 PHP 文件权限