问题描述
任何人都可以帮我找到我的脚本的替代代码,因为它需要 Mysqlnd ,许多在线服务器没有这个,所以如果我使用这个代码它会给我这个错误
致命错误:调用未定义的方法mysqli_stmt :: get_result()
因此,我希望有人将我的代码更改为mysqli版本。
我的代码:
$ page_id = mysqli_real_escape_string($ con,$ page_id);
$ select_query = $ con> prepare(选择ID,标题,图片,费用,Vid,来自ID =?的怪物的内容);
$ select_query-> bind_param('i',$ page_id);
$ select_query-> execute();
$ result = $ select_query-> get_result();
while($ row = mysqli_fetch_array($ result,MYSQL_ASSOC))
{
$ post_id = $ row ['ID'];
$ post_title = $ row ['Title'];
更新1
if(isset($ _ GET ['ID'])){
$ page_id = $ _GET ['ID'];
$ page_id = mysqli_real_escape_string($ con,$ page_id);
$ select_query = $ con> prepare(选择ID,标题,图片,费用,Vid,来自ID =?的怪物的内容);
$ select_query-> execute();
$ select_query-> bind_result($ post_id,$ post_title,$ post_image,$ post_cost,$ post_vid,$ post_cont);
while($ select_query-> fetch()){
$ post_id = $ row ['ID'];
$ post_title = $ row ['Title'];
$ post_image = $ row ['image'];
$ post_cost = $ row ['Cost'];
$ post_vid = $ row ['Vid'];
$ post_cont = $ row ['content'];
$ sign ='$';
$ sign = mysql_real_escape_string($ sign);
?>
更新3
if(isset($ _ GET ['ID'])){
$ page_id = $ _GET ['ID'];
$ select_query =(选择ID,标题,图片,费用,视频,来自ID =?的小怪的内容);
$ select_query-> execute();
$ select_query-> bind_result($ post_id,$ post_title,$ post_image,$ post_cost,$ post_vid,$ post_content);
$ b $ while($ select_query-> fetch())
echo'Post ID:',$ post_id,'< br>',
'Post title:', $ POST_TITLE;
{
仅适用于PHP> = 5.3.0。
我建议使用取而代之。
另外,您不需要转义任何在 bind_param
中使用的字符串。
pre $ $ select_query-> execute( );
$ select_query-> bind_result($ post_id,$ post_title,$ post_image,$ post_cost,$ post_vid,$ post_content);
while($ select_query-> fetch()){
//对绑定的结果变量进行处理,例如
echo'Post ID:',$ post_id,' < br>'
'发布标题:',$ post_title;
}
Anyone help me to find the alternative code for my script because it requires Mysqlnd and many online servers don't have this so if I use this code It will give me this error
Fatal error: Call to undefined method mysqli_stmt::get_result()
So I want someone to change my code into mysqli version.
My Code:
$page_id = mysqli_real_escape_string($con, $page_id);
$select_query = $con->prepare("select ID, Title, image, Cost, Vid, content from mobs where ID=?");
$select_query->bind_param('i', $page_id);
$select_query->execute();
$result = $select_query->get_result();
while ($row = mysqli_fetch_array($result, MYSQL_ASSOC))
{
$post_id = $row['ID'];
$post_title = $row['Title'];
Update 1
if(isset($_GET['ID'])){
$page_id = $_GET['ID'];
$page_id = mysqli_real_escape_string($con, $page_id);
$select_query = $con->prepare("select ID, Title, image, Cost, Vid, content from mobs where ID=?");
$select_query->execute();
$select_query->bind_result($post_id, $post_title, $post_image, $post_cost, $post_vid, $post_cont);
while ($select_query->fetch()) {
$post_id = $row['ID'];
$post_title = $row['Title'];
$post_image = $row['image'];
$post_cost = $row['Cost'];
$post_vid = $row['Vid'];
$post_cont= $row['content'];
$sign = '$';
$sign = mysql_real_escape_string($sign);
?>
Update 3
if(isset($_GET['ID'])){
$page_id = $_GET['ID'];
$select_query = ("select ID, Title, image, Cost, Vid, content from mobs where ID=?");
$select_query->execute();
$select_query->bind_result($post_id, $post_title, $post_image, $post_cost, $post_vid, $post_content);
while ($select_query->fetch())
echo 'Post ID:', $post_id, '<br>',
'Post title: ', $post_title;
{
mysqli_stmt::get_result
is only available in PHP >= 5.3.0.
I suggest using bind_result
instead.
Also, you don't need to escape any strings used in bind_param
.
$select_query->execute();
$select_query->bind_result($post_id, $post_title, $post_image, $post_cost, $post_vid, $post_content);
while ($select_query->fetch()) {
// do stuff with the bound result variables, eg
echo 'Post ID:', $post_id, '<br>'
'Post title: ', $post_title;
}
这篇关于PHP脚本从Mysqlnd转换为mysqli的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!