如何从mysql程序获取laravel端的数据?

问题描述 投票:0回答:1

在使用 mysql 8 的 laravel 8 站点上,我创建了一个带有 1 个输入和 2 个输出参数的过程:

DELIMITER $$

DROP PROCEDURE IF EXISTS getObjectsCount $$

CREATE DEFINER=`lardev`@`localhost` PROCEDURE `getObjectsCount`( IN in_objectType varchar(100), OUT retCount bigint unsigned, OUT totalUsersCount bigint unsigned  )
BEGIN


IF in_objectType = 'users_without_active_tasks' THEN
    select count(*) into retCount from users where users.id not in (select distinct tasks.creator_id from tasks where tasks.status = 'T');
END IF;

IF in_objectType = 'users_without_completed_tasks' THEN
    select count(*) into retCount from users where users.id not in (select distinct tasks.creator_id from tasks where tasks.status = 'D');
END IF;

SELECT concat('retCount is ', retCount);
select count(*) into totalUsersCount from users;


END$$
DELIMITER ;

并称其为:

call getObjectsCount('users_without_completed_tasks', @returnCount, @totalUsersCount);
select @returnCount, @totalUsersCount;

我得到了有效的结果。

但是当我尝试从 php 页面运行相同的程序时,例如:

$data = DB::select("call getObjectsCount('users_without_completed_tasks', @returnCount, @totalUsersCount)");
dd($data);

我得到了奇怪的输出:

+"concat('in_objectType is ', in_objectType)": "in_objectType is users_without_completed_tasks"

看起来该方法在服务器上不起作用。

我可以通过什么方式从mysql程序获取laravel端的数据?

"laravel/framework": "^10.34.2"
Mysql 8.0.34-0ubuntu0.22.04.1

提前致谢!

mysql laravel
1个回答
0
投票

尝试使用具有多个语句的

select
方法。

$data = DB::select("call getObjectsCount('users_without_completed_tasks', @returnCount, @totalUsersCount); select @returnCount as returnCount, @totalUsersCount as totalUsersCount;");
dd($data);

© www.soinside.com 2019 - 2024. All rights reserved.