dongwa3808 2015-09-12 07:44
浏览 39
已采纳

HY093:参数数量错误 - 位置

I am getting the HY093 error on the $q->execute line.

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: parameter was not defined'

$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:

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.

Any idea what I might be missing?

  • 写回答

1条回答 默认 最新

  • duanhua5523 2015-09-12 07:57
    关注

    You are mixing the two ways of working with 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:

    $data = array("Your Name", 
                  "Notes", 
                  "35.1338614", 
                  "-106.64091979999999", 
                  "8512",
                  "1442043552884");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历