mysqli选择错误

时间:2014-08-02 11:07:28

标签: mysqli

我有这个选择:

<?php
$stmt2 = $mysqli->prepare("SELECT `country`, COUNT(`country`) AS `numar` FROM logs GROUP BY country where username = '$username'");
$stmt2->execute();
mysqli_stmt_bind_result($stmt2, $country, $numar);
$stmt2->store_result();
if($stmt2->num_rows > 0)  //To check if the row exists
  {
      while (mysqli_stmt_fetch($stmt2))
{
  echo "<tr>                

                    <tr>
                    <td class=\"nn\" style=\"text-align:center;\" align=center>$country</td>
                    <td class=\"nn\" style=\"text-align:center;\" align=center>$numar</td>

                    </tr>
                    ";

        }           

} else {
echo"<tr>
<td colspan=\"5\" class=nn><div style=\"text-align:center;\">Not have websites in your account! Click <a href=\"addwebsite\">here</a> to add a website!</div></td>
</tr>";
}   
?>

运行此选择时,返回此错误:致命错误:在第115行的/nginx/html/site/reports.php中的非对象上调用成员函数execute(),第115行与select一致!我尝试使用and选择但同样的错误!哪里有问题?

1 个答案:

答案 0 :(得分:0)

如下所述纠正sql

$stmt2 = $mysqli->prepare("SELECT `country`, COUNT(`country`) AS `numar` FROM logs where username = '$username' GROUP BY country ");