PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Monday, February 21, 2022

[FIXED] Call to MySQL user defined function in CakePHP 3

 February 21, 2022     cakephp, cakephp-3.0, mysql-routines, php     No comments   

Issue

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.

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

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.

Here is my cakePHP 3 code.

$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.
);

Solution

I got solution.. Here it is.

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


Answered By - Akshay Vaghasiya
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,209,872

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing