[英]HY093: Wrong number of parameters - positional
I am getting the HY093 error on the $q->execute
line. 我在
$q->execute
行上收到HY093错误。
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: parameter was not defined'
致命错误:消息为'SQLSTATE [HY093]:未捕获的异常'PDOException':无效的参数号:未定义参数'
$stmt = "INSERT INTO `survey`(`user`,`notes`,`lat`,`lon`,`acc`,`timestampx`) VALUES(?,?,?,?,?,?)";
$q = sql::$db->prepare($stmt);
var_dump($data);
$q -> execute($data);
and my vardump echos: 和我的vardump回声:
array(6) {
["user"]=>string(9) "Your Name"
["notes"]=>string(5) "Notes"
["lat"]=>string(10) "35.1338614"
["lon"]=>string(19) "-106.64091979999999"
["acc"]=>string(4) "8512"
["time"]=>string(13) "1442043552884"
}
When I copy and paste this data into MySQL (replacing the ? with the quoted strings) it works. 当我将此数据复制并粘贴到MySQL中(用引号引起的字符串替换?)时,它可以工作。
Any idea what I might be missing? 知道我可能会缺少什么吗?
You are mixing the two ways of working with PHP. 您正在混合使用PHP的两种方式。 If you want to use an associative array to supply the bind values, your query needs to reference them by name, with a colon (
:
) to indicate these are bind variables: 如果你想使用关联数组来提供绑定值,你的查询需要按名称引用,请用冒号(
:
),以表明它们是绑定变量:
$stmt = "INSERT INTO `survey`" .
"(`user`,`notes`,`lat`,`lon`,`acc`,`timestampx`) " .
"VALUES(:user, :notes, :lat, :lon, :acc, :time)";
Alternatively, you could leave $query
as is and provide the parameters in a simple, positional, array: 或者,您可以保留
$query
,并以简单的位置数组提供参数:
$data = array("Your Name",
"Notes",
"35.1338614",
"-106.64091979999999",
"8512",
"1442043552884");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.