【发布时间】:2017-05-01 09:33:08
【问题描述】:
我正在努力让我的$num_rows 工作。它一直在工作,现在不行了。阅读这个网站,有人建议我在我的服务器上安装MySqlnd,因为像fetch_array 和get_result 这样的东西不起作用,现在我希望我从来没有安装它。 (我应该卸载它吗?)
我一直在尝试很多不同的方法来尝试让$num_rows 工作 - 以及其他功能 - 我不知道什么是对还是错了。你能帮我吗 ?我得到的错误是:
Fatal error: Call to undefined method mysqli::stmt() in /var/www/html/checkcontact.php on line 34
第 34 行是:$result = $con->stmt($query);
这是我的代码:
<?php
require('dbConnect.php');
//post all contacts in my phone as a JSON array
$json = $_POST['phonenumber'];
//decode the JSON
$array = json_decode($json);
//bind
$query = "SELECT * FROM user WHERE username = ?";
$stmt = $con->prepare($query) or die(mysqli_error($con));
$stmt->bind_param('s', $phonenumber);
//for each value of phone_number in the array, call it $phonenumber
foreach ($array as $value)
{
$phonenumber = $value->phone_number;
$stmt->execute();
$result = $con->stmt($query);
//$result = $stmt->get_result();
//$stmt->store_result();
//$num_rows = $stmt->num_rows();
//$result = mysqli_query($con, $query);
if ($result->$num_rows > 0) {
// while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
// while($row = mysqli_fetch_assoc($result)){
// $contact_id = $row['user_id'];
// echo $contact_id;
echo "number of phone numbers in the user table is " . $num_rows . "<br>";
}
}
?>
编辑: 这是我的 dbConnect.php 文件,根据要求:
<?php
define ('HOST', 'localhost');
define ('USER', 'bob');
define ('PASS', 'password');
define ('DB', 'mydb');
$con = NEW MySQLi("localhost", "bob", "password", "mydb");
if ($con->connect_error) {
die("Connection failed: " . $con->connect_error);
}
?>
【问题讨论】:
-
看来问题不在您的
$num_rows方法中。您可以发布 dbConnect.php 文件吗?这就是您的$con变量的来源吗? (不要忘记删除密码!) -
@Clemenz 谢谢,编辑帖子以包含我的 dbConnect.php。
标签: php mysql-num-rows mysqlnd