mysqli_result无法转换为字符串

时间:2013-11-26 07:01:28

标签: php

首先,感谢您阅读本文。如何解决我的问题

CODE

$roomid = CMS::$MySql->Query("SELECT room_id FROM user_roomvisits WHERE user_id ='".$users['id']."' ORDER BY entry_timestamp DESC LIMIT 1");
$room = CMS::$MySql->Query("SELECT caption FROM rooms WHERE id ='".$roomid."'"); 

并得到了错误:

捕获致命错误:类mysqli_result的对象无法转换为字符串。

这里是mysql类

<?php
   class MySql{
private $Link;
private $Statement;
public $Result = null;
private $FetchRows = Array();

public function __construct($Data)
{
    $this->Link = new MySQLi($Data['mysql.hostname'], $Data['mysql.username'], $Data['mysql.password'], $Data['mysql.database']);
}

public function Query($Query)
{
    if (isset($this->Statement))
    {
        $this->Statement->Close();
        $this->Statement = null;
    }

    return $this->Link->query($Query);
}



public function Prepare($Query)
{
    if (isset($this->Statement))
    {
        $this->Statement->Close();
    }

    $this->Statement = $this->Link->prepare($Query);


}

public function Execute($FuncArgs = null)
{
    if (!is_array($FuncArgs))
    {
        $FuncArgs = func_get_args();
    }

    $Args = Array('');

    foreach ($FuncArgs as &$Arg)
    {
        $Args[0] .= substr(gettype($Arg), 0, 1);
        $Args[] =& $Arg;
    }

    call_user_func_array(Array($this->Statement, 'bind_param'), $Args);
    if (!$this->Statement->Execute())
    {
        exit('Execute Stmt Error: '.$this->Statement->error);
    }

    return $this->Statement;
}

public function Fetch($Columns)
{
    if (!is_array($Columns))
    {
        $Columns = func_get_args();
    }

    if ($this->Result == null)
    {
        $this->Result = array_combine($Columns, $Columns);
        $Args = Array();

        foreach ($Columns as $Column)
        {
            $Args[] =& $this->Result[$Column];
        }

        call_user_func_array(Array($this->Statement, 'bind_result'), $Args);
    }

    $RowsLeft = $this->Statement->fetch();

    if (!$RowsLeft)
    {
        self::Clear();
        return false;
    }

    return $this->Result;
}

&GT;

这些是PDO的mysql类吗?

1 个答案:

答案 0 :(得分:0)

$roomid = CMS::$MySql->Query("SELECT room_id FROM user_roomvisits WHERE user_id ='".$users['id']."' ORDER BY entry_timestamp DESC LIMIT 1");
while($row=mysql_fetch_array($roomid)){
    $rumid=$row[0];
}
$room = CMS::$MySql->Query("SELECT caption FROM rooms WHERE id ='".$rumid."'"); 

mysql查询的结果是对象。你无法回应物体

使用var_dump()print_r()查看其结构