inserting with PHP or with stored procedure

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
wtf
Forum Contributor
Posts: 331
Joined: Thu Nov 03, 2005 5:27 pm

inserting with PHP or with stored procedure

Post 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!
User avatar
christian_phpbeginner
Forum Contributor
Posts: 136
Joined: Sat Jun 03, 2006 2:43 pm
Location: Java

Re: inserting with PHP or with stored procedure

Post 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
ody
Forum Contributor
Posts: 147
Joined: Sat Mar 27, 2004 4:42 am
Location: ManchesterUK

Post by ody »

One disadvantage is portability to other database systems.
User avatar
wtf
Forum Contributor
Posts: 331
Joined: Thu Nov 03, 2005 5:27 pm

Post 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
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post 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.
Post Reply