【问题标题】:PHP Script convertsion from Mysqlnd to mysqliPHP 脚本从 Mysqlnd 转换为 mysqli
【发布时间】:2014-03-20 03:55:33
【问题描述】:

任何人都可以帮我找到我的脚本的替代代码,因为它需要 Mysqlnd 并且许多在线服务器没有这个,所以如果我使用这个代码它会给我这个错误

Fatal error: Call to undefined method mysqli_stmt::get_result()

所以我希望有人将我的代码更改为 mysqli 版本。

我的代码:

  $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'];

更新 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);


?>

更新 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;
 {

【问题讨论】:

    标签: php html mysqli mysqlnd


    【解决方案1】:

    mysqli_stmt::get_result 仅在 PHP >= 5.3.0 中可用。

    我建议改用bind_result

    另外,您不需要转义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;
    }
    

    【讨论】:

    • 在这样做之后它给了我这个错误Notice: Undefined variable: select line 18Fatal error: Call to a member function bind_result() on a non-object
    • @user3423422 只是一个错字。现已修复
    • 我修复了这个问题,但现在什么都没有显示:D 请检查更新
    • @user3423422 同样,停止使用mysqli_real_escape_string尤其是 mysql_real_escape_string。你不需要它们。我不希望显示任何内容,因为您没有显示任何内容
    • @user3423422 另外,没有$row 变量。 bind_result 将值直接分配给您的变量。你不需要$post_id = $row['ID'] 和其他人
    猜你喜欢
    • 2014-07-02
    • 2015-04-11
    • 2013-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-06-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多