这个问题在这里已经有答案了:
我可以在php中混合mysql api吗(4个答案)
两年前关门了。
每当我在phpmyadmin中尝试时,下面的查询都可以正常工作:
SELECT CAST(DATETIME AS DATE), Provider, COUNT(Provider)
FROM purchases
GROUP BY CAST(DATETIME AS DATE), Provider
ORDER BY CAST(DATETIME AS DATE) DESC
然而,当我把它放在php脚本中时,我总是收到一个布尔值:
$sql="SELECT CAST(DATETIME AS DATE), Provider, COUNT(Provider)
FROM purchases
GROUP BY CAST(DATETIME AS DATE), Provider
ORDER BY CAST(DATETIME AS DATE) DESC";
if (mysqli_query($con,$sql))
{
$result = mysql_query($sql);
while($row = mysql_fetch_assoc($result)) {
echo $row['CAST(DATETIME AS DATE)'];
echo $row['Provider'];
echo $row['COUNT(Provider)'];
}
}
else
{
echo "Error creating table: " . mysqli_error($con);
}
mysqli_close($con)
;
我真的很想得到一些关于如何解决这个问题的建议。
1条答案
按热度按时间ktca8awb1#
此代码如下所示,所以它的工作很好
你用
mysqli
在所有查询中检查$result
否则比打印记录有价值error
消息已打印