adam84 Posted June 29, 2006 Share Posted June 29, 2006 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 Link to comment https://forums.phpfreaks.com/topic/13241-sql-queries/ Share on other sites More sharing options...
lead2gold Posted June 29, 2006 Share Posted June 29, 2006 [!--quoteo(post=389409:date=Jun 29 2006, 03:40 PM:name=adam84)--][div class=\'quotetop\']QUOTE(adam84 @ Jun 29 2006, 03:40 PM) [snapback]389409[/snapback][/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 Quote Link to comment https://forums.phpfreaks.com/topic/13241-sql-queries/#findComment-50994 Share on other sites More sharing options...
fenway Posted July 3, 2006 Share Posted July 3, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/13241-sql-queries/#findComment-52309 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.