2014-09-01 29 views
0

我使用OOP概念,從而使用的mysqli連接到我的數據庫,但在這裏我得到的「數據庫查詢不同步的,你無法運行此命令」的錯誤這就是爲什麼我使用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); 
    } 
+0

你的'free_result()'方法正在調用它自己。 – shudder 2014-09-01 05:51:02

+0

它工作時,我取代$ this-> free_result($結果);與mysqli_free_result($ reult),但是當我打電話給我的過程@commentOutput是一個輸出參數,它給va; ue作爲空我檢查運行在工作臺評論輸出值不爲null – 2014-09-01 06:38:10

回答

0

我把它給輸出沒有足夠的聲譽。所以我不能添加評論。

我想你的程序沒有數據要返回。

你可以嘗試在你的程序的末尾添加

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"); 

希望可以幫助你。

+0

同樣的事情,我試過那裏只有我沒有得到任何數據後,從用戶選擇查詢 – 2014-09-01 08:36:34

+0

@ user3622633我運行你的代碼,它工作正常。除free_result()之外,它調用它自己。 – 2014-09-01 08:59:10