MySql / PHP查询返回空

时间:2013-04-04 22:01:24

标签: php mysql sql

这是我的代码:

$result = mysqli_query($dbconnection, Data::followUser($user_id, $followUser_id));

$result在此处返回空白。

课程followUser

中的

Data方法

public static function followUser($user_id, $followUser_id) {
    global $database;

    $query = "
        SELECT * 
        FROM profile_follow
        WHERE user_id = '{$user_id}' 
            AND follow_id = '{$followUser_id}';";

    $result = $database -> query($query);
    $num = mysqli_num_rows($result);

    if ($num  < 1) {
        $toast = "Follow";

        $query = "
        INSERT INTO profile_follow (user_id, follow_id)
            VALUES ('{$user_id}', '{$followUser_id}');";

        $result = $database -> query($query);


    } elseif ($num > 0) {
        $toast = "Unfollow";

        $query = "
        DELETE FROM profile_follow
        WHERE user_id = '{$user_id}' 
            AND follow_id = '{$followUser_id}';";


        $result = $database -> query($query);

    }

    return $toast;
}

我已经验证了该函数在回显$ toast时正常工作。根据条件,它是FollowUnfollow。我不认为我出来的时候正在处理它?<​​/ p>

补充:

以下是我用$ result做的事情:

if ($result == "Follow") {
            $output["result"] = "Follow";
            echo json_encode($output);
    } elseif ($result == "Unfollow") {
            $output["result"] = "Unfollow";
            echo json_encode($output);
    }

1 个答案:

答案 0 :(得分:1)

这一切都完成了什么?你基本上得到了:

mysqli_query($dbconnection, 'Unfollow');

这不是任何有效的查询。 $result不是空的。这是一个布尔值false,表示查询失败......