Welcome Guest, Not a member yet? Register   Sign In
How to call a Stored Procedure using DataMapper ORM?
#1

[eluser]stoan09[/eluser]
Is it possible to call a MySQL Stored Procedure using DataMapper ORM, I can't find this on the Documentation, I have be goggling as well but nothing. Thanx
#2

[eluser]WanWizard[/eluser]
What exactly do you want to achieve?

Datamapper is an ORM, which uses models to provide an object representation of records in a table. It's not made to run arbitrary queries.

If your stored procedure returns full records of a table, so it's result can be mapped to a model, you could add a method to the model that calls the stored procedure using standard DB calls. You can then call _process_query(), passing the CI_DB_Result object from your custom query, to convert the result into Datamapper objects.

Note that the resultset MUST include the 'id' column.
#3

[eluser]stoan09[/eluser]
I'm building a location based events listing app. I store events on the db with coordinates,(latitude and longitude), so im looking to write a stored procedure that will take advantage of MySQL's geometry features. So the stored procedure would accept latitude and longitude ans distance as parameters and return events within the specified distance. The events table has the field "id"

Thank you
#4

[eluser]WanWizard[/eluser]
Then it should be possible using the method I described.
#5

[eluser]stoan09[/eluser]
I haven't started to write my code but If I understand what you described above, it would go something like this

$e = new Event();

$result = $e->query("call my_stored_proc_name(my_parameters)");
#6

[eluser]WanWizard[/eluser]
No, what I meant was something like

Code:
class Event extends Datamapper
{
    public function mymethod()
    {
        $result = $this->db->query('call my_stored_proc_name(my_parameters)');
        $this->_process_query($result);
        return $this;
    }
}
#7

[eluser]stoan09[/eluser]
Thank you, Making sense so far. I think it will make more sense once I have started creating my objects. I like to separate my class that defines my object with the one that contains methods for the object. As my stored procedure will return more than one event, I assume this line will return a list or array of objects?

<code>
return $this;
</code>




Theme © iAndrew 2016 - Forum software by © MyBB