Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
查询在mysql上运行良好,但在php中出现错误_Php_Mysql - Fatal编程技术网

查询在mysql上运行良好,但在php中出现错误

查询在mysql上运行良好,但在php中出现错误,php,mysql,Php,Mysql,但当我直接在mysql中使用它时,效果很好。什么问题 更新 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select sum(quantity)from orders o,product p,order2product op where o.order_id = ' a

但当我直接在mysql中使用它时,效果很好。什么问题

更新

  You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select sum(quantity)from orders o,product p,order2product op where o.order_id = ' at line 1
$sql=mysql\u query(“将@today=CAST(NOW()设置为CHAR(64)),@forday=CAST(日期添加(NOW(),间隔-1天)作为日期);从订单o、产品p、订单2product op中选择总和(数量),其中o.order\u id=op.order\u id和op.product\u id=p.product\u id和订单日期<@today和订单日期>@DAY”)或die(mysql\u error());
$existCount=mysql_num_rows($sql);//数一数行数。
如果($existCount>0)
{
while($row=mysql\u fetch\u数组($sql))
{
$dayQuantity=$row[“总和(数量)”];
}
}

请发布您的php代码。请查看更新部分。该字符串中有两个查询,而不是一个查询
mysql_*()
(已弃用且不应使用)不支持此功能。你需要分别发送两个查询,或者更新到支持多查询的mysqli*(),或者同时发送两个查询。我尝试了$sql=$mysqli->query(“SET@today=CAST(NOW()AS CHAR(64)),@dayed=CAST(DATE\u ADD(NOW(),INTERVAL-1天)AS DATE);选择sum(quantity)来自订单o、产品p、订单2产品op,其中o.order_id=op.order_id和op.product_id=p.product_id和订单日期<@今天和订单日期>@昨天”);但它不起作用,我可以省去理解它的语法的麻烦。虽然您肯定应该从mysql_*()切换,但您可以尝试提交带有变量的SQL。只需将这些垃圾移到
SELECT
语句中,比如
selectsum(quantity)from orders o,product p,order2product op,其中o.order_id=op.order_id和op.product_id=p.product_id和order_date之间的日期加(NOW(),INTERVAL-1天)和NOW()
  You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select sum(quantity)from orders o,product p,order2product op where o.order_id = ' at line 1
 $sql = mysql_query("SET @today=CAST(NOW() AS CHAR(64)),@yesterday=CAST(DATE_ADD(NOW(),INTERVAL - 1 DAY) AS DATE); select sum(quantity)from orders o,product p,order2product op where o.order_id = op.order_id AND op.product_id = p.product_id AND order_date < @today AND order_date > @yesterday") or die(mysql_error());

$existCount = mysql_num_rows($sql); // count the row nums.
if($existCount > 0)
{
 while($row = mysql_fetch_array($sql))
 {
    $dayQuantity = $row["sum(quantity)"];   
 }
}