Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DATA CONCATENATION: - PHP or MySQL?

Status
Not open for further replies.

MichaelHooker

Programmer
Mar 17, 2006
70
0
0
GB
A very simple theoretical question, I hope. No code is necessary.

If the result on the webpage is to be a concatenation of fields from a MySQL database, is it more efficient to use CONCAT in the MySQL query and retrieve a single item into the php result array, or to retrieve the fields separately and concatenate them in the php code with stops or commas?

No other MySQL or php processing of the data is required: it is to be displayed just as it comes.

I've tried both approaches and can't detect any difference, but the dataset is currently comparatively small.

Thanks

Michael Hooker
 
i suspect the answer will depend on your scaling model and on the hardware architecture you are using.

in general, unless you have multiple webservers to a single database or some other unbalanced architecture, then i'd expect to see speed advantages in using the database to concatenate data that comes, itself, from the database.
 
Thank you. I don't know what a "scaling model" is, and not a clue what "hardware architecture" might be. If it's unbalanced, does it fall over? I know I do.

All I know is that my webspace provider uses Linux for my domain on a shared server.

I'll take your advice and concatenate within the MySQL. It has the advantage of simplifying the php, the less "columns" in the array of results to deal with, the better.

Thanks

Michael Hooker
 
It depends entirely on the situation. If your web server is also busy serving a zillion other sites, it may be a good option to put this load on the database server. If your database server is also busy serving a lot of databases to other machines, it may pay off to put this load on the web server. But if the servers you use are not pushing the limits, I would not worry about that too much.
 
Thanks. I have no idea how many other users I share with (or perhaps more to the point, how much they use the servers). I guess it's something to start worrying about only if things start slowing down.

Michael Hooker
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top