Jump to content


Photo

Sql Queries


  • Please log in to reply
2 replies to this topic

#1 adam84

adam84
  • Members
  • PipPipPip
  • Advanced Member
  • 289 posts
  • LocationOntario, Canada

Posted 29 June 2006 - 07:40 PM

Hi,

I am creating an application by using both PHP and mySQL. My question is about efficiency between PHP and mySQL. What would be a more efficient way of programming. To query the database and store the returned data in variables and perform the manicpulation on the variables. Or inser thte mathatical formula into your select statement and let mySQL handle the calculations? I search google and yahoo for this, but I was unable to find anything relevant.

Thanks
If 'Ctrl + v' and 'Ctrl + c' didnt exist, I don't think I would ever program...

#2 lead2gold

lead2gold
  • Members
  • PipPipPip
  • Advanced Member
  • 164 posts
  • LocationOttawa, On

Posted 29 June 2006 - 08:32 PM

[!--quoteo(post=389409:date=Jun 29 2006, 03:40 PM:name=adam84)--][div class=\'quotetop\']QUOTE(adam84 @ Jun 29 2006, 03:40 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Hi,

I am creating an application by using both PHP and mySQL. My question is about efficiency between PHP and mySQL. What would be a more efficient way of programming. To query the database and store the returned data in variables and perform the manicpulation on the variables. Or inser thte mathatical formula into your select statement and let mySQL handle the calculations? I search google and yahoo for this, but I was unable to find anything relevant.

Thanks
[/quote]

There are people here who are more knowledgable then me on this topic, but php is one gigantic compiler reading and writing code on the fly (slow compared to a binary action like an sql transaction). I would think it would be much faster to do as much math as you can using sql (assuming it only takes 1 insert line) then to do it with php.

But the trade off is how many calculations you intend to preform. It might be easier from a maintenance point of view to use php.

I would think: use sql if it's a simple math that can be done without retrieving the info to work with first. Otherwise retrieve the record, do your math and insert the data back.

Chris

#3 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 03 July 2006 - 05:02 AM

The big performance hit is actually retrieving the result set itself... so if you're getting back hundreds of rows just to do some math, SQL is better; however, since it's just a bunch of statements, it becomes difficult to put together semantic data sets, so middleware if often the right choice.  It really depends.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users