dongshao1873
2015-01-11 18:56
浏览 58
已采纳

Mysqli使用预准备语句获取数组

I am in the process of making my mysql queries prepared in an attempt to increase security, however I have a problem when I attempt to fetch the results of a prepared statement. I can successfully fetch one row of data however I have had no success fetching an array of data. All of the research I have done has provided examples that either don't work or are way too complicated.

My Current Code

if ($stmt = $dbc->prepare("SELECT city FROM users WHERE id = ? LIMIT 1")) {
$stmt->bind_param('i', $id);  // Bind id to parameter.
$stmt->execute();    // Execute the prepared query.
$stmt->store_result();

 // get variables from result.
$stmt->bind_result($city);
$stmt->fetch();
}

This is my current code which only returns one result.

图片转代码服务由CSDN问答提供 功能建议

我正在准备我的mysql查询以试图提高安全性,但是我遇到了问题 我试图获取准备好的声明的结果。 我可以成功获取一行数据但是我没有成功获取数据数组。 我所做的所有研究都提供了不起作用或过于复杂的例子。

我的当前代码 \ n

  if($ stmt = $ dbc-> prepare(“SELECT city FROM users WHERE id =?LIMIT 1”)){
 $ stmt-> bind_param('i',$ id)  ;  //将id绑定到参数。
 $ stmt-> execute();  //执行准备好的查询。
 $ stmt-> store_result(); 
 
 //从结果中获取变量。
 $ stmt-> bind_result($ city); 
 $ stmt-> fetch  (); 
} 
   
 
 

这是我当前的代码,只返回一个结果。

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题