Note that there are some explanatory texts on larger screens.

plurals
  1. POCreate Stored Procedure from PHP
    text
    copied!<p>I am creating a database setup script which create and setup database on fly. The mysql user I use have full previledge to create stored procedure. My database server is different from my application server.</p> <p>I am able to create user, then database, then select database, then create tables, then insert some data into tables, then create views etc..But at last when I create stored procedures I am facing issues.</p> <p>Following a the sql to create procedure </p> <pre class="lang-sql prettyprint-override"><code>CREATE DEFINER=`newuser`@`192.168.0.10` PROCEDURE `AppCounts_Stagewise_Monthly_Weekly` (IN FILTERTYPE INTEGER) BEGIN IF(FILTERTYPE = 0) THEN SELECT base_user_id, stage, COUNT(vw_application.id) AS app_counts, WEEK(DATE) AS `week`, YEAR(DATE) AS `year` FROM vw_application WHERE DATE_SUB(CURDATE(),INTERVAL 7 DAY) &lt;= DATE(DATE) AND DATE(DATE) &lt;= CURDATE() GROUP BY vw_application.stage, base_user_id; ELSE SELECT base_user_id, stage, COUNT(vw_application.id) AS app_counts, MONTH(DATE) AS `month`, YEAR(DATE) AS `year` FROM vw_application WHERE DATE_SUB(CURDATE(),INTERVAL 30 DAY) &lt;= DATE(DATE) AND DATE(DATE) &lt;= CURDATE() GROUP BY vw_application.stage, base_user_id; END IF; END; </code></pre> <p>The <code>create procedure</code>s SQLs like above are separated by a special separator and put in a file. I open the file and explode each create script by the separator to get each create statement in an array and execute them using zend db adapter. </p> <pre><code>$data = file_get_contents($this-&gt;_specimenDbFiles['ROUTINES']); $data = explode('--', $data); foreach($data as $key =&gt; $value) { $clientDbAdaptor-&gt;query($value); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload