Page 1 of 1

inserting with PHP or with stored procedure

Posted: Tue Sep 12, 2006 10:24 pm
by wtf
Greets,

i'm having bit of dillema when it comes to manipulating db lately

Usually, php code looks like this

Code: Select all

$db->execute( 'INSERT INTO TABLE( ROW, ROW2, ROW3 ) VALUES( $VAL, $VAL, $VAL );
With my current project I'm able to use stored procedures etc and started passing parameters to SP and let the SP handle the rest of it,

Code: Select all

$db->execute( 'SELECT STOR_PROC( $VAL, $VAL, $VAL ) );
and the stored procedure takes care of insertion etc. This of course assume that the input is sanitized etc.

I'm just curious over any advantages/disadvantages anyone can see/have experienced with this approach etc.


Regards!

Re: inserting with PHP or with stored procedure

Posted: Sat Sep 16, 2006 12:41 am
by christian_phpbeginner
Yes, I am curious too about this. If someone might has experienced the advantages / disadvantages of using Stored Procedure and want to share a bit of suggestions or comments ?

Thanks,
Chris

Posted: Sat Sep 16, 2006 8:57 am
by ody
One disadvantage is portability to other database systems.

Posted: Sat Sep 16, 2006 1:41 pm
by wtf
OK, I've done some searching and it's the flame war all over the place. Lots of really good articles howevery mostly related to MSSQL Server.
Check it out

Posted: Sat Sep 16, 2006 1:48 pm
by onion2k
If you're *just* inserting some data then there's little practical difference. Using a stored procedure allows you to change things without visiting the code, but that's not a huge advantage unless your database team are seperated from your development team somehow.

However, that said, stored procedures aren't really for doing that. They're basically functions that run on your database. For example, if you were inserting a new product and you wanted to check if it's SKU existed in one of several different tables, a stored procedure would enable you to check without having to pass information back and forth between a script and your database. That would save a few round trips, lots of memory, and make everything quicker.