大佬教程收集整理的这篇文章主要介绍了php – MySQLI Prepared Statement:num_rows&fetch_assoc,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
$mysqli = mysqli_connect($config['host'],$config['user'],$config['pass'],$config['db']); $stmt = $mysqli->prepare("SELECT * FROM licences WHERE generated = ?"); $stmt->bind_param('i',$core['id']); $result = $stmt->execute(); $stmt->store_result(); if ($stmt->num_rows >= "1") { while($data = $result->fetch_assoc()){ //Loop through results here $data[] } }else{ echo "0 records found"; }
我觉得有点厚颜无耻只是要求代码,但它是我的情况的工作演示,我觉得我需要最终了解实际发生了什么.太感谢了!
代码看起来有点不确定,但是它是如何工作的:
建立连接,准备一个语句,绑定参数并执行它,一切都很好.
$result = $stmt->execute(); //execute() tries to fetch a result set. Returns true on succes,false on failure. $stmt->store_result(); //store_result() "binds" the last given answer to the statement-object for... reasons. Now we can use it! if ($stmt->num_rows >= "1") { //Uses the stored result and counts the rows. while($data = $result->fetch_assoc()){ //And here,the answer-object is turned into an array-(object) // which can be worked with nicely. //It loops trough all entries in the array. } }else{ echo "0 records found"; }
以上是大佬教程为你收集整理的php – MySQLI Prepared Statement:num_rows&fetch_assoc全部内容,希望文章能够帮你解决php – MySQLI Prepared Statement:num_rows&fetch_assoc所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。