pdo - 如何正确地将我的变量绑定到我的令牌?
问题描述
我不知道是什么导致了这个错误,我已经筋疲力尽了。我不知道如何解决这个问题。
警告:PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: 绑定变量的数量与 C:\wamp64\www\myproject-dev\public\viajes\orden_mantenimiento\controller.php 中的令牌数量不匹配第77行
当我尝试执行我的 create 方法时会发生这种情况,因此这是整个方法:
if ($type == 'create') {
$Records = $request->models;
foreach ($Records as $rec) {
if (isset($request->pky)) {
$fky = $request->fky;
$rec->$fky = $request->pky;
}
$aError = Validate($rec);
$statement = $conn->prepare('INSERT INTO order (id, idVehiculo, idTipo, fecha, kilometraje, horaIn, horaSal, proyecto, jefeProy, aprobadoPor, descripcion)
VALUES (:id, :idVehiculo, idTipo, :fecha, :kilometraje, :horaIn, :horaSal, :proyecto, :jefeProy, :aprobadoPor, descripcion)');
$statement->bindValue(':id', $rec->id);
$statement->bindValue(':idVehiculo', $rec->idVehiculo);
$statement->bindValue(':idTipo', $rec->idTipo);
$statement->bindValue(':fecha', $rec->fecha);
$statement->bindValue(':kilometraje', $rec->kilometraje);
$statement->bindvalue(':horaIn', $rec->horaIn);
$statement->bindvalue(':horaSal', $rec->horaSal);
$statement->bindValue(':proyecto', $rec->proyecto);
$statement->bindValue(':jefeProy', $rec->jefeProy);
$statement->bindValue(':aprobadoPor', $rec->aprobadoPor);
$statement->bindValue(':descripcion', $rec->descripcion);
if (!$statement->execute()) { // **========================== THIS IS LINE 77 ===================**
$aErrInfo = $statement->errorInfo();
$aError = array();
$aError[] = array('success' => false);
$aError[] = array('msg' => $aErrInfo[1]);
$aError[] = array('error' => $aErrInfo[2]);
$respuesta["errors"] = $aError;
echo "statement error".$respuesta;
} else {
$rec->id = $conn->lastInsertId();
$respuesta["data"] = $rec;
echo "Data bound.";
}
} else {
$respuesta["errors"] = $aError;
echo "ERROR";
}
}
}
提前非常感谢。
解决方案
推荐阅读
- sql - id 与外键不同的 SQL 命令 (MariaDB)
- c# - 来自另一种语言的 golang c-shared 库回调
- python - 如何在 Autosys 中捕获 Python 脚本的错误代码?
- python - 在 PIL 中保存文件时出现 TypeError
- excel - 有没有办法将 SaveCopyAs 与对话框、自定义名称和选择当前文件类型(格式)(52 或 .xlsm)一起使用
- ios - UIPickerView 仅填充“?”
- tailwind-css - TailwindCSS 使用带有占位符颜色的 @apply
- python-3.x - 可视化给定 numpy 数组的值分布
- python - GeoDjango 在模型中的模板表单上显示地图
- php - MTURK API:从 PHP 访问分配对象的私有字段?