Is it worth coding in stored procedures or in the code (or separate class).
I read somewhere that stored procedures are faster in their execution, because they sit on the database, and it doesn’t need to make the interpretation stage when it reads php code.
I like coding in a separate file the mysql code that I need and refer it from there. Would it make a difference if I used stored procedures?
I recently came upon this problem.
Using stored procedures on the DB is much faster, when you create the SP it compiles it down into an intermediate code that it can run faster than having to parse standard SQL statements at run time. ALSO the biggest advantage of SP’s is that you can pass in some params, and you can make the SP do a whole load of work on the DB, which can be controlled using IF ELSE statements and CASES, this also keeps traffic between your application and the DB to a minimum.
One final advantage to SP’s, you can keep the DB implementation seperate from your application implementation, this mean that if say you do an insert in 10 different places in your application, then you change the way the insert needs to be done, you need to go back and change that insert in those 10 different places, whereas if you used an SP to wrap up the insert you can then just change that SP on the fly and the application doesnt need to know 😉
If your already scripting out your SQL code, then your practically 75% home on writing SP’s
EDIT: If you use the PHP MySQLi, you may or may not be aware that calling stored procedures returns 2 rowsets as opposed to standard queries that only return 1, but this isn’t too bigger problem as long as you know its coming 🙂