php - mysqli no result from prepare statement? -
i have prepare statement user login. works fine, return 1 if login correct.
after need user id , user name (from bd, think better put input direct session).
but have no result in $rst["id"];
, $rst["user"];
what problem?
$stmt = $mysqli_link->prepare("select id, user cadastro binary user = ? , binary senha = ?"); $stmt->bind_param('ss', $user, $senha); $stmt->execute(); $stmt->store_result(); $num = $stmt->num_rows; if($num > 0) { //retorna os dados banco $rst = $stmt->fetch(); $id = $rst["id"]; $user = $rst["user"]; $sessionid = md5(time()); echo"$user - $id - $sessionid"; } ?>
thank you!
you need use $rst = $stmt->fetch_assoc
. $stmt->fetch()
used after using $stmt->bind_result()
, fetches results variables named in call.
note using fetch_assoc()
prepared statement requires have mysqlnd driver installed.