<?php
function exceptionHandler($e)
{
var_dump($e);
}
function shutdown()
{
echo 'Скрипт успешно завершился', PHP_EOL;
}
register_shutdown_function('shutdown');
set_exception_handler('exceptionHandler');
test();
/*
object(Error)#1 (7) { ["message":protected] => string(33) "Call to undefined function test()", ... }
Скрипт успешно завершился
*/
SELECT `p`.*,
COUNT(`op`.`id`) AS `ordersCount`,
IFNULL(SUM(`op`.`count`), 0) AS `countOrdersCount`
IFNULL(SUM(`op`.`price` * `op`.`count`), 0) AS `ordersSum`
FROM `products` AS `p`
LEFT JOIN `orders_products` AS `op` ON `op`.`item_id` = `p`.`id`
LEFT JOIN `orders` AS `o` ON `o`.`id` = `op`.`order_id`
AND `o`.`date` > '2020-01-01'
AND `o`.`status` != 2
WHERE `p`.`active` = '1'
GROUP BY `p`.`id`
ORDER BY `p`.`id` DESC
LIMIT 0, 25