我有一个名为 SP_MemberIncomeGraph(@p)的过程 这是程序的主体
DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `SP_MemberIncomeGraph`(IN `parent_id` INT(11) UNSIGNED)
NO SQL
SELECT
t1.earned_on,
ifnull(t2.dtc_bonus, 0) as dtc_bonus,
ifnull(t2.leadership_bonus, 0) as leadership_bonus,
ifnull(t2.si_bonus, 0) as si_bonus
FROM (
(SELECT (CURRENT_DATE - INTERVAL t.n - 1 DAY) AS earned_on
FROM tally t) t1
LEFT JOIN (SELECT date(created_at) AS created_at
,coalesce(SUM(CASE WHEN source='OR' then amount else 0 END),0) as leadership_bonus
,coalesce(SUM(CASE WHEN source='DTC' then amount else 0 END),0) as dtc_bonus
,coalesce(SUM(CASE WHEN source='SI' then amount else 0 END),0) as si_bonus
FROM incomes
WHERE
incomes.created_at BETWEEN (CURDATE() - INTERVAL 30 DAY) AND CURDATE() AND
user_id=parent_id GROUP BY created_at)AS t2
ON t2.created_at = t1.earned_on
) ORDER BY earned_on desc LIMIT 30$$
DELIMITER ;
现在从普通的php mysql语句调用它:
<?php
$mysqli = new mysqli("localhost", "root", "123456", "hashpartner_new");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
}
if (!($res = $mysqli->query("CALL SP_MemberIncomeGraph(12)"))) {
echo "CALL failed: (" . $mysqli->errno . ") " . $mysqli->error;
}
while ($row = $res->fetch_assoc()){
print_r($row);
}
?>
我得到了与存储过程结果相同的确切结果。从laravel调用相同的过程时,我得到不同的结果,可能是什么原因?我不知道。
这是laravel的调用语句
DB::select('call SP_MemberIncomeGraph (?)', [$this->id]);
这是上面声明的结果:
{"earned_on":"2018-12-04","dtc_bonus":"0.00","leadership_bonus":"0.00","si_bonus":"0.00"},{"earned_on":"2018-12-03","dtc_bonus":"100.00","leadership_bonus":"0.00","si_bonus":"0.00"},{"earned_on":"2018-12-02","dtc_bonus":"0.00","leadership_bonus":"0.00","si_bonus":"0.00"},{"earned_on":"2018-12-01","dtc_bonus":"0.00","leadership_bonus":"0.00","si_bonus":"0.00"},{"earned_on":"2018-11-30","dtc_bonus":"0.00","leadership_bonus":"0.00","si_bonus":"0.00"},{"earned_on":"2018-11-29","dtc_bonus":"0.00","leadership_bonus":"0.00","si_bonus":"0.00"},{"earned_on":"2018-11-28","dtc_bonus":"0.00","leadership_bonus":"0.00","si_bonus":"0.00"},{"earned_on":"2018-11-27","dtc_bonus":"0.00","leadership_bonus":"0.00","si_bonus":"0.00"},{"earned_on":"2018-11-26","dtc_bonus":"0.00","leadership_bonus":"0.00","si_bonus":"0.00"},{"earned_on":"2018-11-25","dtc_bonus":"0.00","leadership_bonus":"0.00","si_bonus":"0.00"},{"earned_on":"2018-11-24","dtc_bonus":"0.00","leadership_bonus":"0.00","si_bonus":"0.00"},{"earned_on":"2018-11-23","dtc_bonus":"0.00","leadership_bonus":"0.00","si_bonus":"0.00"},{"earned_on":"2018-11-22","dtc_bonus":"0.00","leadership_bonus":"0.00","si_bonus":"0.00"},{"earned_on":"2018-11-21","dtc_bonus":"0.00","leadership_bonus":"0.00","si_bonus":"0.00"},{"earned_on":"2018-11-20","dtc_bonus":"0.00","leadership_bonus":"0.00","si_bonus":"0.00"},{"earned_on":"2018-11-19","dtc_bonus":"0.00","leadership_bonus":"0.00","si_bonus":"0.00"},{"earned_on":"2018-11-18","dtc_bonus":"0.00","leadership_bonus":"0.00","si_bonus":"0.00"},{"earned_on":"2018-11-17","dtc_bonus":"0.00","leadership_bonus":"0.00","si_bonus":"0.00"},{"earned_on":"2018-11-16","dtc_bonus":"0.00","leadership_bonus":"0.00","si_bonus":"0.00"},{"earned_on":"2018-11-15","dtc_bonus":"0.00","leadership_bonus":"0.00","si_bonus":"0.00"},{"earned_on":"2018-11-14","dtc_bonus":"0.00","leadership_bonus":"0.00","si_bonus":"0.00"},{"earned_on":"2018-11-13","dtc_bonus":"0.00","leadership_bonus":"0.00","si_bonus":"0.00"},{"earned_on":"2018-11-12","dtc_bonus":"0.00","leadership_bonus":"0.00","si_bonus":"0.00"},{"earned_on":"2018-11-11","dtc_bonus":"0.00","leadership_bonus":"0.00","si_bonus":"0.00"},{"earned_on":"2018-11-10","dtc_bonus":"0.00","leadership_bonus":"0.00","si_bonus":"0.00"},{"earned_on":"2018-11-09","dtc_bonus":"0.00","leadership_bonus":"0.00","si_bonus":"0.00"},{"earned_on":"2018-11-08","dtc_bonus":"0.00","leadership_bonus":"0.00","si_bonus":"0.00"},{"earned_on":"2018-11-07","dtc_bonus":"0.00","leadership_bonus":"0.00","si_bonus":"0.00"},{"earned_on":"2018-11-06","dtc_bonus":"0.00","leadership_bonus":"0.00","si_bonus":"0.00"},{"earned_on":"2018-11-05","dtc_bonus":"0.00","leadership_bonus":"0.00","si_bonus":"0.00"}