php连接数据库问题,求大神指导

SeanLam111 2017-11-23 12:52:09
<?php
include_once 'Conn/Conn.php';
$sql="select * from user";
$stmt=mysqli_prepare($con, $sql);
$result=mysqli_execute($stmt) or die(mysqli_error($con));

while($res=mysqli_fetch_assoc($result)){
echo $res['name']." ".$res['pwd']." ".$res['type'];
}
mysqli_close($con);
?>
然后查不到数据 一直报错
Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in C:\wamp\www\PHP_final_129\index.php on line 7
...全文
234 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
hongmei85 2017-11-24
  • 打赏
  • 举报
回复

$sql = "SELECT `title`,`content`,`create_time` FROM `think_form`";

if($stmt = mysqli_prepare($conn, $sql)){
  //mysqli_stmt_bind_param($stmt, "s", $key);
  mysqli_stmt_execute($stmt);
  mysqli_stmt_bind_result($stmt, $title, $content, $create_time);
  while (mysqli_stmt_fetch($stmt)) {
    echo $title . ' ' . $content . ' ' . $create_time . '<br/>';
  }
}
xuzuning 2017-11-23
  • 打赏
  • 举报
回复
不是有 bool mysqli_stmt_fetch ( mysqli_stmt stmt ) 吗?
SeanLam111 2017-11-23
  • 打赏
  • 举报
回复
但是我已经用prepare了呀,只能用execute,我想知道mysqli用面向过程的方法如何查询返回一个结果集 ,用来判断用户登录是否成功
xuzuning 2017-11-23
  • 打赏
  • 举报
回复
mysqli_execute 是 mysqli_stmt_execute 的别名
果酱很好吃 2017-11-23
  • 打赏
  • 举报
回复
mysqli_execute 是 mysqli_stmt_execute的别名,只会返回 true 或 false 查询用mysqli_query

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧