我试图在 8 列的表中插入数据,但它不起作用。我正在使用 mysql 版本 5.7.11 。然而,当我将其减少到 6 列时,它会起作用,7 列也无法工作。
请在下面找到表格及其 php 代码
- 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/