Php 绑定_结果mysqli不工作

Php 绑定_结果mysqli不工作,php,mysqli,Php,Mysqli,我用xampp在localhost中创建了一个网站。 现在我把它放在一个服务器上,什么都不工作了 本地主机: $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(); $sb4

我用xampp在localhost中创建了一个网站。 现在我把它放在一个服务器上,什么都不工作了

本地主机:

$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_结果不起作用,因此我了解到需要更改以绑定_结果:

$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();
但它给了我这个:

错误:警告:mysqli_stmt::bind_result[mysqli stmt.bind result]: 绑定变量的数量与准备语句中的字段数量不匹配


出了什么问题?

为了实现您的目标,没有必要获得结果。您不需要创建新变量来包含bind_结果

而不是这个,

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

 $on124->bind_result($id, $ip, $hora);
您的新变量$id、$ip、$hora现在可以使用了

此外,为了能够从准备好的语句中获取num_行,您需要存储结果,如下所示

$on124->store_result();
在调用num_行之前

您也可以在以后使用

$on124->free_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();
$on124->bind_result($id, $ip, $hora);
$on124->store_result();
$sb4154 = $on124->num_rows;
$on124->fetch();
$on124->free_result();
$on124->close();

注意,我编辑它是为了提供澄清的全部内容。它是完美的,谢谢!我可以使用select*from。。。?绑定结果需要有变量,或者可以为空?比如:绑定结果;再次感谢您在bind_result中,您必须在查询中命名特定变量。实际上,您可以为它们命名任何您想要的名称,它们不必与表键匹配。它们按照它们出现的顺序进行标识,很像bind_param。然后你通过使用fetchnote得到它们,我修改了上面的答案,将其包括在内;我以前忘了。在查询中命名键实际上是一种很好的做法;虽然select*对于小表来说可能并不重要,但它确实会使系统陷入困境,所以进入这个习惯是很好的,好吧!非常感谢你,你帮了我很多!!!!很高兴有你这样的人在这里!