我有这个 PHP-MySQL 插入代码:
$sqlTeeth = "INSERT INTO teeth (id_logged, patient_id, one, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, eightteen, nineteen, twenty, twone, twtwo, twthree, twfour, twfive, twsix, twseven, tweight, twnine, thirty, thone, thtwo, date_now) VALUES (:id_logged, :patient_id, :one, :two, :three, :four, :five, :six, :seven, :eight, :nine, :ten, :eleven, :twelve, :thirteen,
:fourteen, :fifteen, :sixteen, :lone, :ltwo, :lthree, :lfour, :lfive, :lsix, :lseven, :leight, :lnine, :lten, :leleven, :ltwelve, :lthirteen,
:lfourteen, :lfifteen, :lsixteen)";
$sqlTeethStmt = $conn->prepare($sqlTeeth);
$sqlTeethStmt->bindValue(":id_logged", $id_logged);
$sqlTeethStmt->bindValue(":patient_id", $patient_id);
$sqlTeethStmt->bindValue(":one", $one);
$sqlTeethStmt->bindValue(":two", $two);
$sqlTeethStmt->bindValue(":three", $three);
$sqlTeethStmt->bindValue(":four", $four);
$sqlTeethStmt->bindValue(":five", $five);
$sqlTeethStmt->bindValue(":six", $six);
$sqlTeethStmt->bindValue(":seven", $seven);
$sqlTeethStmt->bindValue(":eight", $eight);
$sqlTeethStmt->bindValue(":nine", $nine);
$sqlTeethStmt->bindValue(":ten", $ten);
$sqlTeethStmt->bindValue(":eleven", $eleven);
$sqlTeethStmt->bindValue(":twelve", $twelve);
$sqlTeethStmt->bindValue(":thirteen", $thirteen);
$sqlTeethStmt->bindValue(":fourteen", $fourteen);
$sqlTeethStmt->bindValue(":fifteen", $fifteen);
$sqlTeethStmt->bindValue(":sixteen", $sixteen);
$sqlTeethStmt->bindValue(":lone", $lone);
$sqlTeethStmt->bindValue(":ltwo", $ltwo);
$sqlTeethStmt->bindValue(":lthree", $lthree);
$sqlTeethStmt->bindValue(":lfour", $lfour);
$sqlTeethStmt->bindValue(":lfive", $lfive);
$sqlTeethStmt->bindValue(":lsix", $lsix);
$sqlTeethStmt->bindValue(":lseven", $lseven);
$sqlTeethStmt->bindValue(":leight", $leight);
$sqlTeethStmt->bindValue(":lnine", $lnine);
$sqlTeethStmt->bindValue(":lten", $lten);
$sqlTeethStmt->bindValue(":leleven", $leleven);
$sqlTeethStmt->bindValue(":ltwelve", $ltwelve);
$sqlTeethStmt->bindValue(":lthirteen", $lthirteen);
$sqlTeethStmt->bindValue(":lfourteen", $lfourteen);
$sqlTeethStmt->bindValue(":lfifteen", $lfifteen);
$sqlTeethStmt->bindValue(":lsixteen", $lsixteen);
$sqlTeethStmt->execute();
当我向数据库添加内容时,出现此错误:
SQLSTATE[21S01]:插入值列表与列列表不匹配:1136 列计数与第 1 行的值计数不匹配
任何帮助表示赞赏。
您的数据库表有 35 列
id_logged, patient_id, one, two, three, four, five, six, seven, eight, nine, ten, eleven, twelve, thirteen, fourteen, fifteen, sixteen, seventeen, eightteen, nineteen, twenty, twone, twtwo, twthree, twfour, twfive, twsix, twseven, tweight, twnine, thirty, thone, thtwo, date_now
您传递的值是 34 列
VALUES (:id_logged, :patient_id, :one, :two, :three, :four, :five, :six, :seven, :eight, :nine, :ten, :eleven, :twelve, :thirteen,
:fourteen, :fifteen, :sixteen, :lone, :ltwo, :lthree, :lfour, :lfive, :lsix, :lseven, :leight, :lnine, :lten, :leleven, :ltwelve, :lthirteen, :lfourteen, :lfifteen, :lsixteen)
列的不匹配会给您带来错误。
您忘记传递 date_now 列的值。一旦你通过了,错误就会被解决
SQLSTATE[21S01]:插入值列表与列列表不匹配:1136 列计数与第 1 行的值计数不匹配
前面的答案绝对解释了根本问题,但也许理解错误报告也很有帮助。它分为两部分:
插入值列表与列列表不匹配:SQL 语句首先由列列表组成,然后由值列表组成,这两者不匹配。
1136 列计数与第 1 行的值计数不匹配问题是列出的值的数量与列出的列的数量不同。
SQL 错误代码写得相当简洁,可能看起来很晦涩,但是一旦你将它们分解,其含义通常非常简单。
另一个“用户案例”,我有触发器来存储表更改...添加新列给出了此错误(尽管新字段/值计数是正确的)...我必须删除触发器才能获取新字段已接受...
就我而言,当我使用 Seeder 并忘记删除之前从 Seeder 中的所有其他项目中删除的一个字段时,发生了此错误