调用未定义的方法mysqli :: result()

时间:2017-04-10 07:44:28

标签: php mysql

你能帮我们找出错误吗,谢谢你的帮助。

  

调用未定义的方法mysqli :: result()

<?php

    function user_exists($username) {
        $db = mysqli_connect("localhost","root","","sample");
        $query = $db->query("SELECT COUNT(`id`) FROM `users` WHERE username = '$username'");
        return ($db->result($query, 0) == 1) ? true : false;
    }

 ?>

1 个答案:

答案 0 :(得分:0)

尝试这样:

    function user_exists($username) {
        $db = mysqli_connect("localhost","root","","sample");
        $result = $db->query("SELECT `id` FROM `users` WHERE username = '$username'");
        return ($result->num_rows ? true : false);}