du8589840 2013-09-10 15:47
浏览 50
已采纳

Mysqli查询返回空字符串

In progress of this issue:

Mysqli query return empty results

This is my php code:

<?php 

error_reporting(E_ALL);
ini_set('display_errors', 1);


$mysqli2 = new mysqli('');

    if (mysqli_connect_errno()) {
    printf("Connect failed: %s
", mysqli_connect_error());
    exit();
   }

    $sql2 = "SELECT message FROM wall_workouts_names WHERE id = '43' ";

    $stmt2 = $mysqli2->prepare($sql2) or trigger_error($mysqli2->error."[$sql2]");

    $stmt2->execute();

    $stmt2->bind_result($message);

    $stmt2->store_result();

     $stmt2->fetch();

    if($stmt2->num_rows > 0)
       echo $message;    
   else
        echo 'empty';    

?>

From this code i get empty string as a result.

This is my table in phpmyadmin

enter image description here

When i run the same code but with this query:

 $sql2 = "SELECT workout_name FROM wall_workouts_names WHERE id = '43' ";

My echo is "t", as is should be.

But when i run this query:

 $sql2 = "SELECT message FROM wall_workouts_names WHERE id = '43' ";

I get empty string, something like this: "".

I dont understand what im doing wrong.

  • 写回答

1条回答 默认 最新

  • duanpei4455 2013-09-10 16:38
    关注

    According to this commenter, the

    "proper procedure order is: prepare -> execute -> store_result -> bind -> fetch."

    I notice that you are calling store_result() AFTER you call bind_result(). Does changing the order of those calls make any difference?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 像这种代码要怎么跑起来?
  • ¥15 怎么改成循环输入删除(语言-c语言)
  • ¥15 安卓C读取/dev/fastpipe屏幕像素数据
  • ¥15 pyqt5tools安装失败
  • ¥15 mmdetection
  • ¥15 nginx代理报502的错误
  • ¥100 当AWR1843发送完设置的固定帧后,如何使其再发送第一次的帧
  • ¥15 图示五个参数的模型校正是用什么方法做出来的。如何建立其他模型
  • ¥100 描述一下元器件的基本功能,pcba板的基本原理
  • ¥15 STM32无法向设备写入固件