Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialWayne Comber
8,169 PointsWhat is best practice for data manipulation like concatenation?
Just wondering what is considered best practice for this sort of data manipulation? e.g If I am writing a script in PHP, am I better off to manipulate the data all in the database using SQL and bring in just the final results or bring the data into PHP and concatenate and manipulate it there? No doubt there are performance issues involved, so is it faster for the database to do these sorts of operations, or the server/compiler in the front end? Also, is it more secure to do all the manipulation in the database before presenting it to the front end? Thanks :)
1 Answer
Steven Parker
231,248 PointsThere's probably very little performance difference, since you'd be sending a more complicated query but receiving a more compact response. Since I tend to be more "code first" than "data first" in design philosophy, I'd massage the data in the server code. But I don't think it would clearly constitute a "best practice".
Security would only be a factor if manipulating the data in the database prevents the transmission of something sensitive that would be removed later in the server. Even so, it's only a minor improvement if the server still has the ability to query the other elements directly.