duanlipeng4136
2015-09-07 19:52
浏览 62
已采纳

使用mysqli的SELECT返回null

I'm trying to select a row from a table using mysqli but all I can get is a bunch of null values and I don't really know why. The same query works using normal php mysql and if I try to perform the same query on phpMyAdmin using the parameter I pass goes through fine.

Here's the code:

$con = mysqli_connect('localhost', 'user', 'pass',"db");

if (mysqli_connect_errno()){
    die("Failed to connect to MySQL: " . mysqli_connect_error());
}
$coupon = $_GET['coupon'];
$sql = mysqli_prepare($con, "SELECT * FROM coupon WHERE coupon=?");
$sql->bind_param('s', $coupon);
$sql->execute();
$sql->store_result();
echo $sql;

returns

"affected_rows":null,
"insert_id":null,
"num_rows":null,
"param_count":null,
"field_count":null,
"errno":null,
"error":null,
"error_list":null,
"sqlstate":null,
"id":null

I already tried to search for an answer either here and on google but I couldn't find anything close to my problem. What am I doing wrong?

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

我正在尝试使用mysqli从表中选择一行,但我能得到的是一堆空值 我真的不知道为什么。 相同的查询使用普通的php mysql工作,如果我尝试使用参数在phpMyAdmin上执行相同的查询,我会通过罚款。

这是代码: \ n

  $ con = mysqli_connect('localhost','user','pass',“db”); 
 
if(mysqli_connect_errno()){
 die(“无法连接到MySQL:  “.mysqli_connect_error()); 
} 
 $ coupon = $ _GET ['coupon']; 
 $ sql = mysqli_prepare($ con,”SELECT * FROM coupon WHERE coupon =?“); 
 $ sql-  > bind_param('s',$ coupon); 
 $ sql-> execute(); 
 $ sql-> store_result(); 
echo $ sql; 
   \  ñ
 

返回

 <代码> “affected_rows”:空,
 “个INSERT_ID”:空,
 “个NUM_ROWS”:空,
 “个param_count”:空 ,
 “FIELD_COUNT”:空,
 “错误号”:空,
 “错误”:空,
 “error_list”:空,
 “SQLSTATE”:空,\ N “标识”:空
    
 
 

我已经尝试在这里和谷歌搜索答案,但我找不到任何接近我问题的答案。 我做错了什么?

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

2条回答 默认 最新

相关推荐 更多相似问题