Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

String performacne: PHP vs MySQL [duplicate]

Tags:

php

mysql

Are there any performance concerns of note when using MySQL's CONCAT() function in a select query? Is it faster/slower/negligible to do a simple select, and format strings for a view using PHP after the result set from the database is returned? Or is a more complicated SQL query with multiple calls to CONCAT() that returns a string already formatted for the view a better approach?

ie is this:

select CONCAT(lastname, ', ', firstname) from people;

Faster/Slower/No difference from this:

<?php
    $query = 'Select lastname, firstname from people';
    ...

    $name = $data['lastname'] . ', ' . $data['firstname']; //OR
    $name = sprintf("%s, %s", $data['lastname'], $data['firstname']);
?>
like image 817
Sam Heuck Avatar asked Feb 27 '26 01:02

Sam Heuck


1 Answers

You're better off in almost all cases by doing filtering and data massaging with the SQL engine versus on the web server.

like image 198
LJ Wilson Avatar answered Mar 01 '26 15:03

LJ Wilson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!