Rumah > Artikel > pembangunan bahagian belakang > 为什么无法使用php中mysqli的准备语句进行数据库中数据的查询(绑定参数或者绑定结果),项目急用!该如何处理
为什么无法使用php中mysqli的准备语句进行数据库中数据的查询(绑定参数或者绑定结果),项目急用!
代码如下:
<!-- Code highlighting produced by Actipro CodeHighlighter (freeware) http://www.CodeHighlighter.com/ --> <?php /* 利用mysqli扩展来绑定结果 */ //新建服务器连接 $mysqli=new mysqli('localhost','root','root','searcdb'); //创建查询 $query="SELECT adminName,adminPwd FROM admininfo"; //创建语句对象 $stmt=$mysqli->stmt_init(); //为执行准备语句 $stmt->prepare($query); //执行语句 $stmt->execute(); //绑定结果参数 $stmt->bind_result($name,$pwd); //循环处理结果并输出数据 while($stmt->fetch()){ printf("%s, %s, %s <br>",$name,$pwd); } //恢复语句资源 $stmt->close(); //关闭连接 $mysqli->close(); ?>
function selectLink($oid){ $sql = "select o.oid,l.lid,c.cid,comName,comPrice,ordTime from mis_order o,mis_link l,mis_commodity c where o.oid=l.lid and c.cid=l.cid and o.oid=?"; $stmt = $this->mysqli->prepare($sql); $stmt->bind_param("i",$oid); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($oid,$lid,$cid,$comName,$comPrice,$ordTime); $rows = $stmt->affected_rows; if($rows > 0){ $arrLink = array(); while($stmt->fetch()){ $arr = array( "oid" => $oid, "lid" => $lid, "cid" => $cid, "comName" => $comName, "comPrice" => $comPrice, "ordTime" => $ordTime ); array_push($arrLink,$arr); } return $arrLink; }else{ echo "查询订单明细失败!<br>"; } } <div class="clear"> </div>