How to call a Stored Procedure using DataMapper ORM?

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

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.

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

Then it should be possible using the method I described.

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)");

No, what I meant was something like

class Event extends Datamapper
    public function mymethod()
        $result = $this->db->query('call my_stored_proc_name(my_parameters)');
        return $this;

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?

return $this;

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.