在CakePHP 3中调用MySQL用户定义的函数

时间:2022-09-21 00:00:39

I'm working on cakePHP 3. I have a user defined function(UDF or Routine) in mysql database. That function takes two parameters and returns an integer value. I have to match that returned value in MySQL where clause.

我正在使用cakePHP 3.我在mysql数据库中有一个用户定义的函数(UDF或Routine)。该函数接受两个参数并返回一个整数值。我必须在MySQL where子句中匹配返回的值。

I know mysql query to use that function. i.e,

我知道mysql查询使用该功能。即,

SELECT customer_id FROM table_name WHERE routine_name(param1, param2)=1;    //param1 is 'customer_id' which I have written after SELECT

But I don't know that how to build this query in cakePHP 3. If anyone knows the solution, answer will be appreciate.

但我不知道如何在cakePHP 3中构建此查询。如果有人知道解决方案,答案将是欣赏。

Here is my cakePHP 3 code.

这是我的cakePHP 3代码。

$purchasesTable = TableRegistry::get("Purchases");
$query = $purchasesTable->find();

$fields = ['customer_id'];
$query->select($fields);
$query->where(
    //    Routine/Function call should be here as per MySQL query.
    //    So, I think here I have to do something.
);

1 个解决方案

#1


1  

I got solution.. Here it is.

我得到了解决方案......就在这里。

$abc = $query->func()->function_name(['param1' => 'literal']);
$query->where(function ($exp) use ($abc) {
        return $exp->gt($abc, 14);
    });

#1


1  

I got solution.. Here it is.

我得到了解决方案......就在这里。

$abc = $query->func()->function_name(['param1' => 'literal']);
$query->where(function ($exp) use ($abc) {
        return $exp->gt($abc, 14);
    });