We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Calling stored procedure

Does Phalcon supports calling stored procedures? 'Cause I didn't found anything, just a how-to like tutorial http://dragos.musetescu.name/posts/working-with-mysql-stored-procedures-in-phalcon, but it doesn't work.



98.8k

Which part does not work?



33.6k
edited Jul '14

If you go to the Creating a Model and calling a stored procedure section in that page, you can see how he creates a sql query (CALL statement), creates a new instance of that model, and then returns a Phalcon\Mvc\Model\Resultset\Simple. Well, all of that just doesn't returns any data (and I tested the procedure in phpmyadmin previously). One thing happens: or I get a blank page (result of not having a view for ajaxAction), or it just doesn't return anything (AJAX doesn't get to done event). EDIT: I think i've discovered why.



33.6k
edited Jul '14

I've advanced and thinking about what the real problem is: ResultSet\Simple just don't do the work. I've tried a *SELECT FROM table, but it also gives me an empty object. In phpmyadmin works that query, obviously, and I don't see problems from db* dependency ( did a var_dump and the values are OK). It just like ResultSet\Simple* doesn't do the work it has to do. And the code is exactly the same as here http://docs.phalcon.io/es/latest/reference/phql.html#using-raw-sql



33.6k
edited Jul '14

It seems that Phalcon\Mvc\Model\Resultset\Simple has a problem with its constructor (or something). I did a print_r($user->getReadConnection->query($sql)->fetch(), true), and works (using SELECT or my stored procedure).

Why?



98.8k

A ´Resultset´ is returned you have to traverse using a foreach or call ´fetch´ to obtain a row result of executing the SQL statement.



33.6k
Accepted
answer

I tried the other time, and now also doesn't work. I've to be missing something important; doesn't matter, I think I prefer using fetch().