我在判断我的数据库中是否已经存在Facebook用户id时遇到了一些问题(如果不存在,则应将该用户作为新用户接受,否则只需加载canvas应用程序).我在托管服务器上运行了它,没有问题,但在本地主机上,它给了我以下错误:

mysqli_fetch_array()希望参数1是mysqli_result,布尔值在

这是我的代码:

<?
$fb_id = $user_profile['id'];
$locale = $user_profile['locale'];

if ($locale == "nl_NL") {
    // Checking User Data @ WT-Database
    $check1_task = "SELECT * FROM `users` WHERE `fb_id` = " . $fb_id . " LIMIT 0, 30 ";
    $check1_res = mysqli_query($con, $check1_task);
    $checken2 = mysqli_fetch_array($check1_res);
    print $checken2;
    // If the user does not exist @ WT-Database -> insert
    if (!($checken2)) {
        $add = "INSERT INTO users (fb_id, full_name, first_name, last_name, email) VALUES ('$fb_id', '$full_name', '$first_name', '$last_name', '$email')";
        mysqli_query($con, $add);
    }
    // Double-check, the user won't be able to load the app on failure inserting to the database
    if (!($checken2)) {
        echo "Excuse us " . $first_name . ". Something went terribly wrong! Please try again later!";
        exit;
    }
} else {
    include ('sorrylocale.html');
    exit;
}

我已经读到它与我的查询错误有关,但它对我的主机Provider 起了作用,所以这不可能!

推荐答案

mysqli_query()的查询失败,返回false.

把这个放在mysqli_query()后面看看发生了什么.

if (!$check1_res) {
    printf("Error: %s\n", mysqli_error($con));
    exit();
}

有关更多信息:

http://www.php.net/manual/en/mysqli.error.php

Mysql相关问答推荐

嵌套MySQL语句问题

SQL/Pyspark -判断条件

运行简单查询时Prisma预准备语句错误

从insert语句获取新生成的虚拟UUID

Mysql:使用like Select 查询

错误 2020 (HY000): 数据包大于 'max_allowed_pa​​cket' 字节,docker 容器内出现 mysql 错误

错误:此查询集包含对外部查询的引用,并且只能在子查询中使用

避免多个SQL查询的重构代码

为什么order by子句可以利用索引?

查询获取日期之间的可数匹配条目并加入它们以读取用户状态

Golang Gorm:相同的查询构造不同,抛出不同的结果

如何判断嵌套查询返回的元组中的每个条目是否相同?

在 MySQL 中使用三个表进行计算

mysql 5.5;可以从记录中排除表吗?

更改整数时间到日期格式 MM/DD/YY,如 python 中的 datetime.fromtimestamp

终止空闲的mysql连接

MySQL:将日期时间插入其他日期时间字段

授予用户对 MySQL 中有限数量表的访问权限

我可以在 PHP 中使用 PDO 创建数据库吗?

MySQL导入数据库但忽略特定表