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");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 matlab中使用gurobi时报错
  • ¥15 WPF 大屏看板表格背景图片设置
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂