dtntjwkl83750 2014-03-29 06:04
浏览 90

mysqli_query在主机上返回NULL但在本地主机上运行

I have small php web service and I tested it locally and it works. When I uploaded it to bluehost server I get NULL as a result from calling mysqli_query

$con = connect();
    $userName = mysqli_real_escape_string($con, $userName);
    $email = mysqli_real_escape_string($con, $email);

    $query1 = "select * from `users` where `user_name` = '$userName'";

    $res1 = mysqli_query($con, $query1);
//var_dump($res1)  prints NULL

    if ($res1) {
        $count = mysqli_num_rows($res1);

        if ($count == 0) {
            $query2 = "select * from `users` where `email` = '$email'";
            $res2 = mysqli_query($con, $query2);
            if ($res2) {
                $count2 = mysqli_num_rows($res2);
                if ($count2 == 0) {
                    return 0; //not found before
                } else {
                    return 2; //Email already exists
                }
            }
        } else {
            return 1; //user name already exists
        }
    } else {
        return -1;   //Database Error; // always resturned
    }

Edit 1: //Code to connect to database function connect() {

    $con = mysqli_connect("localhost", "user", "pass", "db");
    if (mysqli_connect_errno()) {
        return 0;
    } else {
        return $con;
    }
}

EDIT 2: If I added mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); in the first line at connect() method, I got nothing at all, even the -1 return is not there.

  • 写回答

1条回答 默认 最新

  • douqipi9704 2014-03-29 07:05
    关注

    It was a problem in the database structure and I don't know why mySqli did not show this when I print the error messages. I imported the sql dump file and it worked. Sorry and Thanks for your time.

    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大