TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
View Poll Results: Direct queries vs. Stored procedures
Direct queries 7 70.00%
Stored procedures 3 30.00%
What the hell are you talking about?! 0 0%
Voters: 10. You may not vote on this poll

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 12-13-2007, 05:18 PM   #1 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default Direct queries vs. stored procedures

What would you choose? I go with direct queries. Simpler, faster, portable. What more would I want?
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 12-13-2007, 05:46 PM   #2 (permalink)
The Frequenter
 
ReSpawN's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
ReSpawN is on a distinguished road
Default

Depending on the resultsize, direct queries. If you're getting, lets say a log, it's also easy. But then again, free_result your query since it slows your scripts/site.
__________________
"Life is a bitch, take that bitch on a ride"
Send a message via MSN to ReSpawN
ReSpawN is offline  
Reply With Quote
Old 12-13-2007, 05:53 PM   #3 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

Hmm, I did try stored procedures at one time but PHP was having a lot of issues with the server "going away" as it liked to put it. I thought it was quite humorous anyway. That was just less than a year ago though so it's probably all fixed now, but it was logged as a PHP bug on the PHP bug website. I then went back to direct queries and never looked forward since.

I guess I should really! As for the vote though, I think I'm going to have to go with stored procedures ! I just don't practice what I preach.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 12-13-2007, 07:26 PM   #4 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Ideally stored procedures would be my choice since I like to keep DB related things within the DB. With PHP and MySQL however, I'm still somewhat behind the times because I just don't use stored procedures with that combo. I'd also argue against 'direct queries' being more "simple, faster and portable" than stored procedures (in general terms). I'm not quite sure how xenon thinks otherwise, maybe he can tell us.
Salathe is offline  
Reply With Quote
Old 12-13-2007, 10:51 PM   #5 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

Well, since sql queries and php code go in the same place, you can move your code more freely (without having to worry about moving the procedures aswell). Also, it's faster to write a query than a SP, and I consider wrong writing a SP just for the fun of it (replacing queries with SPs, that is). Of course, if I was to make something more advanced, which strictly required operating a database table or more, I would go with SPs and only capture the result with PHP. But I just don't see the usefullness of SPs in plain queries ("select a from b") or simple operations (like a join, for example). I actually saw people who wrote a SP for everything.

I'm strictly talking about PHP and MySQL here.
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 12-13-2007, 11:09 PM   #6 (permalink)
The Frequenter
 
ReSpawN's Avatar
 
Join Date: Nov 2007
Location: Netherlands
Posts: 460
Thanks: 49
ReSpawN is on a distinguished road
Default

Quote:
Originally Posted by xenon View Post
Well, since sql queries and php code go in the same place, you can move your code more freely (without having to worry about moving the procedures aswell). Also, it's faster to write a query than a SP, and I consider wrong writing a SP just for the fun of it (replacing queries with SPs, that is). Of course, if I was to make something more advanced, which strictly required operating a database table or more, I would go with SPs and only capture the result with PHP. But I just don't see the usefullness of SPs in plain queries ("select a from b") or simple operations (like a join, for example). I actually saw people who wrote a SP for everything.

I'm strictly talking about PHP and MySQL here.
I think I understand where you're going with this. And the way Salathe described it, he's thinking about the in-depth database layout. This is simply for getting the queries.
__________________
"Life is a bitch, take that bitch on a ride"
Send a message via MSN to ReSpawN
ReSpawN is offline  
Reply With Quote
Old 12-14-2007, 02:21 PM   #7 (permalink)
The Addict
 
CoryMathews's Avatar
 
Join Date: Nov 2007
Location: USA
Posts: 256
Thanks: 7
CoryMathews is on a distinguished road
Default

well if you are doing the same query over and over again you should use a sp. since then its already compiled and will run quicker.. but for most querys that you do only one time its not really worth writting the sp.
CoryMathews is offline  
Reply With Quote
Old 03-31-2008, 02:48 PM   #8 (permalink)
The Visitor
 
Erutan409's Avatar
 
Join Date: Sep 2007
Posts: 4
Thanks: 4
Erutan409 is on a distinguished road
Default Gotta love them stored procedures...

I'm using numerous stored procedures/functions. I need them especially for the project I'm working where I work. I have a database server, MySQL, OPC server, which is integrated into our production floor, Visual Basic connector that I'm writing, which links OPC data to my database server, and PHP as a GUI. The VB connector is doing a lot of work. It's looking for updates in the OPC server and saving/sending data to/from the database. I use a lot of stored procedures in my VB app. If I didn't the VB connector would be doing a lot more work than I need it to. Right now I have 1200 lines of code for my stored procedures and functions and I expect it to keep growing.
__________________
There are 10 types of people. Those who understand binary, and those who don't. -Oldy.
Erutan409 is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 12:14 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design