简体   繁体   English

HY093:参数数量错误-位置

[英]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.

相关问题 PDO MYSQL HY093(参数数量错误)发出错误 - PDO MYSQL HY093 (wrong number of parameters) issued incorrectly SQLSTATE [HY093]:参数号无效:混合命名和位置参数 - SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters 消息:SQLSTATE[HY093]:无效的参数号:混合命名和位置参数 - Message: SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters Laravel / Ardent:SQLSTATE [HY093]:无效的参数编号:混合的命名和位置参数 - Laravel/Ardent: SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters PHP PDO:SQLSTATE[HY093]:无效的参数号:混合命名和位置参数 - PHP PDO: SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters Yii2,ActiveQuery,PostgreSQL:SQLSTATE [HY093]:无效的参数编号:混合的命名和位置参数 - Yii2, ActiveQuery, Postgresql: SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters 致命错误:未捕获的PDOException:SQLSTATE [HY093]:无效的参数编号:混合的命名和位置参数位于 - Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters in SQLSTATE [HY093]:无效的参数编号(参数不匹配) - SQLSTATE[HY093]: Invalid parameter number (parameters not match) SQLSTATE [HY093]:无效的参数号:未绑定任何参数 - SQLSTATE[HY093]: Invalid parameter number: no parameters were bound SQLSTATE[HY093] 参数号无效 - SQLSTATE[HY093] Invalid parameter number
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM