2015-08-28 94 views
0

我用xampp在localhost中製作了一個網站。 現在我把它放在一臺服務器上,沒有任何工作了。bind_result mysqli不工作

本地主機:

$on124 = $mysqli_link->prepare("select * from online where ip=? order by id desc LIMIT 1"); 
$on124->bind_param('s', $ip); 
$on124->execute(); 
$result_on124 = $on124->get_result(); 
$sb4154 = $result_on124->num_rows; 
$on124->close(); 

get_result不工作,所以我讀,我需要改變bind_result:

$on124 = $mysqli_link->prepare("select id, ip, hora from online where ip = ? order by id desc LIMIT 1"); 
$on124->bind_param('s', $ip); 
$on124->execute(); 
$result_on124 = $on124->bind_result($id, $ip, $hora); 
$sb4154 = $result_on124->num_rows; 
$on124->close(); 

,但它給了我這樣的:

error: Warning: mysqli_stmt::bind_result() [mysqli-stmt.bind-result]: Number of bind variables doesn't match number of fields in prepared statement.

什麼是錯的?

回答

1

出於您所要做的目的,get_result()是不必要的。您不需要創建一個新變量來包含bind_result()

取而代之的是,

$result_on124 = $on124->bind_result($id, $ip, $hora); 

試試這個

$on124->bind_result($id, $ip, $hora); 

你的新變量$id, $ip, $hora現在已經準備好使用。

也能夠從一份聲明中得到num_rows,你將需要存儲的結果,像這樣

$on124->store_result(); 

調用num_rows

您還可以免費這之前之後使用

$on124->free_result(); 

- 編輯爲clarification-- 下面是完整的東西

$on124 = $mysqli_link->prepare("select id, ip, hora from online where ip = ? order by id desc LIMIT 1"); 
$on124->bind_param('s', $ip); 
$on124->execute(); 
$on124->bind_result($id, $ip, $hora); 
$on124->store_result(); 
$sb4154 = $on124->num_rows; 
$on124->fetch(); 
$on124->free_result(); 
$on124->close(); 
+0

謝謝你的回答!我現在就試試吧! –

+0

筆記,我編輯它提供了完整的東西澄清 – nomistic

+0

它是完美的,謝謝!我可以使用select * from ...嗎? bind_result需要有變量或可以爲空? (如:bind_result();)再次感謝您 –