问:这是我的查询代码,如何在prepare语句php中编写相同的代码。
<?php
标头('Content-type:bitmap; charset = utf-8' );
if ( $ &#95; SERVER ['REQUEST&#95; METHOD'] =='POST'){
$ encoded &#95; string = $&#95; POST ['image'];
$ name = $ &#95; POST ['name'];
要求&#95; once('dbconnect.php');
$ sql = “从图像中选择ID,然后按ID ASC排序” ;
$ res = mysqli &#95; query($ con,$ sql);
$ id = 0 ;
而($ row = mysqli &#95; fetch&#95; array($ res)){
$ id = $ row [ 'id' ];
}
$ path = “ uploadedimages / $ id.jpg” ;
$ actualpath = “ http://plantnow.net16.net/$path” ;
$ query = “将图像插入图像(图像,名称)值('$ actualpath','$ name')” ;
如果( mysqli &#95; query($ con,$ query)){
文件&#95; put&#95; contents($ path,base64&#95; decode($ encoded&#95; string));
回显 “成功上传” ;
}
mysqli &#95; close($ con);
}
其他{
回显 “错误” ;
}
?>
答:欢迎使用Findnerd。您可以像这样简单地绑定不同的参数。
$ stmt = $ con-> prepare(“ INSERT INTO images(image,name)VALUES(?,?)”);
$ stmt-> bind_param(“ ss”,$ actualpath,$ name);