我需要在我的代码中对 php for mysql 和 PostgreSQL 做哪些更改?
What changes do i need to do in my code to in php for mysql to PostgreSQL?
$result=mysqli_query($conn, $Sqlquery);
$data_new=array();
foreach($result as $row){
$data_new[]=$row;
}
echo json_encode($data_new,JSON_NUMERIC_CHECK);
我使用上述代码在 mysql 中得到了结果,但在 PostgreSQL 中没有。我也从 mysqli_query 更改为 pg_query
$rs=pg_query($conn, $Sqlquery);
$data_new=array();
while ($row = pg_fetch_row($rs)) {
$data_new[]=$row;
}
echo json_encode($data_new,JSON_NUMERIC_CHECK);
但我的数组中什么也没有。请帮助
查看您在评论中回答我的问题的查询,您似乎向 Postgres 传递了无效查询。
如果您正确地检查和处理了错误,您会发现 FROM_UNIXTIME()
在 SQL 的 PG 方言中不存在,因此您需要找到一个替代方案并调整您的查询它是兼容的。
This question will likely have a replacement that you can use, particularly this answer 建议使用 to_timestamp
- 尽管您需要确保您的列类型兼容(我只能猜测您使用的是什么),但我确定这是罪魁祸首)。
$result=mysqli_query($conn, $Sqlquery);
$data_new=array();
foreach($result as $row){
$data_new[]=$row;
}
echo json_encode($data_new,JSON_NUMERIC_CHECK);
我使用上述代码在 mysql 中得到了结果,但在 PostgreSQL 中没有。我也从 mysqli_query 更改为 pg_query
$rs=pg_query($conn, $Sqlquery);
$data_new=array();
while ($row = pg_fetch_row($rs)) {
$data_new[]=$row;
}
echo json_encode($data_new,JSON_NUMERIC_CHECK);
但我的数组中什么也没有。请帮助
查看您在评论中回答我的问题的查询,您似乎向 Postgres 传递了无效查询。
如果您正确地检查和处理了错误,您会发现 FROM_UNIXTIME()
在 SQL 的 PG 方言中不存在,因此您需要找到一个替代方案并调整您的查询它是兼容的。
This question will likely have a replacement that you can use, particularly this answer 建议使用 to_timestamp
- 尽管您需要确保您的列类型兼容(我只能猜测您使用的是什么),但我确定这是罪魁祸首)。