【问题标题】:No Data Received ERROR for mysqli free resultmysqli 免费结果没有收到数据错误
【发布时间】:2014-09-01 05:37:09
【问题描述】:

我正在使用 OOP 概念来使用 mysqli 连接到我的数据库,但在这里我收到一个错误,因为 “数据库查询不同步,您无法运行此命令” 这就是我使用 mysqli 免费结果的原因,现在我没有收到任何数据作为输出。可能是什么错误?

下面是我的数据库连接类

class MySQLDatabase{
private $connection;
public $last_query;
private $magic_quotes_active;
private $real_escape_string_exists;

function __construct()
{
    $this->open_connection();
    $this->magic_quotes_active = get_magic_quotes_gpc();
    $this->real_escape_string_exists = function_exists( "mysqli_real_escape_string" );
}


public function open_connection()
{
    $this->connection=mysqli_connect(DB_HOST,DB_USER,DB_PASS,DB_NAME) ;
    mysqli_set_charset($this->connection,"utf8");
    if(!$this->connection)
     {
         die("database connecetion failed".mysqli_error($this->connection));
     }
}

public function close_connection()
{
    if(isset($this->connection))
    {
        mysqli_close($this->connection);
        unset($this->connection);
    }
}

public function fetch($result_set)
{
    return mysqli_fetch_array($result_set);
}

public function query($sql)
{
  $this->last_query=$sql;
  $result=$this->connection->query($sql);

    if(!$result)
    {
        die("database query failed ".mysqli_error($this->connection));
    }
    return $result;
}

public function free_result($result)
{
    return $this->free_result($result);
}
}
$database=new MySQLDatabase();

这就是我调用我的程序的方式,但它给出了输出,因为没有收到数据我不知道是什么问题

    $qryCallImgProc = "CALL description (".$postId.","."@commentOutput,@likeCount,@commentCount)";
    $exeCallIgProc = $database->query($qryCallImgProc);
    while($row = $database->fetch($exeCallIgProc))
    {
        print_r($row);
    }  

    $database->free_result($exeCallIgProc);
    $database->close_connection();

    $qryLikeCount = "SELECT * from user";
    $exeLikeCount = $database->query($qryLikeCount);        
    while ($fetchDetails = $database->fetch($exeLikeCount)) {
         print_r($fetchDetails);
     } 

【问题讨论】:

  • 你的 free_result() 方法正在调用自己。
  • 当我更换 $this->free_result($result);使用 mysqli_free_result($reult) 但是当我调用我的过程时,@commentOutput 是一个输出参数,它给出 va;ue as null 我检查了在工作台中运行的注释输出值不为空

标签: php mysql database mysqli


【解决方案1】:

我没有足够的声誉。所以我不能添加评论。

我猜你的程序没有数据要返回。

你可以尝试添加

select 'flag' 

在您的程序结束时。

编辑:

我做了一个这样的程序测试:

create PROCEDURE test_procedure(
       OUT totalCount INT
)
BEGIN
  select 1 into totalCount;
  select totalCount;
end

一切正常。

或者你可以使用这个:

$sql = $mysqli->query("call test_procedure(@output)");
$results = $mysqli->query ("select @output as totalCount");

希望能帮到你。

【讨论】:

  • 我在那里尝试过同样的事情,只是在从用户那里选择查询后我没有得到任何数据
  • @user3622633 我运行你的代码,它工作正常。除了free_result(),它调用自己。
猜你喜欢
  • 2015-11-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多