简体   繁体   English

Order by After Where 子句在 MySQLi PHP 中不起作用

[英]Order by After Where clause not working in MySQLi PHP

Order By After Where is not returning results below is the code and screenshot of not running code. Order By After Where 不返回结果 下面是未运行代码的代码和截图。

SELECT * from `SalesMessages` where `ThreadId`= ? ORDER BY `id` desc Limit 25;

However if I remove bind params it works fine.但是,如果我删除绑定参数,它就可以正常工作。

SELECT * from `SalesMessages` where `ThreadId`=63 ORDER BY `id` desc Limit 25;

Below is screen shot from mySql以下是 mySql 的屏幕截图

mysql query and results mysql查询及结果

HERE IS HOW I WROTE MYSQLI Code这是我如何编写 MYSQLI 代码


    global $conn;
    $arr = array();
    mysqli_set_charset( $conn, 'utf8'); // ALREADY TRIED COMMENTING THIS LINE
    $stmt = $conn->prepare($query);
    $stmt->bind_param('i', $ThreadId);
    try {
        if ($stmt->execute()) {
            $result = $stmt->get_result();
            while ($row = $result->fetch_assoc()) {
                ..SOME CODE..
            }
            if (count($arr) > 0)
                return $arr;
        } else {
            throw "QueryError";
        }
    } catch (Throwable $e) {
        print_r($e);
    }
}

Here is the structure of Table这是表的结构

DATA BASE STRUCTURE数据库结构

I am expecting results from mysql in PHP code as array.我期待 PHP 代码中 mysql 的结果作为数组。

It was connection Error guys Which was using another database which does not had records.这是连接错误的家伙正在使用另一个没有记录的数据库。 Everything else is working fine now.现在其他一切都工作正常。 Actually the table in connected database had no record in required table.实际上连接数据库中的表在所需表中没有记录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM