title: How do I create user-defined sql functions using CakePHP?
body: <p>Consider the example given on <a href="http://www.java2s.com/Tutorial/MySQL/0201__Procedure-Function/Useuserdefinedfunctioninwhereclause.htm" rel="nofollow">this page about creating user-defined functions in SQL and then using the user-defined function in the WHERE clause</a>.</p>
  
  <pre><code>mysql&gt; CREATE FUNCTION myFunction(in_rep_id INT)
      -&gt;      RETURNS INT
      -&gt;      READS SQL DATA
      -&gt; BEGIN
      -&gt;      DECLARE customer_count INT;
      -&gt;
      -&gt;      SELECT COUNT(*)
      -&gt;           INTO customer_count
      -&gt;        FROM employee
      -&gt;       WHERE id=in_rep_id;
      -&gt;
      -&gt;      RETURN(customer_count);
      -&gt;
      -&gt; END$$
  
  mysql&gt; SELECT id,myFunction(id)
      -&gt;   FROM employee
      -&gt;  WHERE myFunction(id)&gt;0
      -&gt;  ORDER BY myFunction(id) desc;
  </code></pre>
  
  <p>How do I replicate this using CakePHP? Do I need to define the function as part of a CakePHP Model? Or is there a way to execute the CREATE FUNCTION syntax but from within CakePHP?</p>
  
  <p>Any help would be appreciated.</p>