2015-08-28 42 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();)再次感谢您 –