如果我有这样一张表:
int VARCHAR int
----------------------------------
1 "U" 1
2 "A" 1
3 "B" 1
然后我像这样通过 php 的 mysqli 运行查询:
$sql = "SELECT * FROM " . parent::GetTableName();
if ($current_user_only == TRUE)
$sql = $sql . " WHERE userID_FK=" . parent::GetUserID();
$result = $this->get_db_con()->query($sql);
if ($result == FALSE)
throw new Exception("SQL exec failed (". __FILE__ . __LINE__ . "): $this->get_db_con()->error");
while ($row = mysqli_fetch_array($result))
{
echo($row[1]);
}
我得到这样的输出:
2 "A" 1
3 "B" 1
1 "U" 1
即结果似乎是按 VARCHAR 列排序的。如果我在 SEQUEL PRO 中运行相同的查询,它会按照我期望的顺序给出结果,这就是它们在表中的输入顺序。
有什么想法吗?
最佳答案
如果没有 order by 子句,我绝不会假定任何特定的顺序。如果您想按 ID 对行进行排序,请使用 order by ID
。
关于php - 如果我在 mysqli::query 中使用 SELECT 语句,默认的 ORDER BY 是什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8301081/