Which of these options is more optimal?
imploding in MySQL
$rsFriends = $cnn->Execute('SELECT CAST(GROUP_CONCAT(id_friend) AS CHAR) AS friends
FROM table_friend
WHERE id_user = '.q($_SESSION['id_user']));
$friends = $rsFriends->fields['friends'];
echo $friends;
vs.
imploding in PHP
$rsFriends = $cnn->Execute('SELECT id_friend
FROM table_friend
WHERE id_user = '.q($_SESSION['id_user']));
while(!$rsFriends->EOF) {
$friends[] = $rsFriends->fields['id_friend'];
$rsFriends->MoveNext();
}
echo implode(',',$friends);
You should probably know that the correct ("most optimal") choice is going to be a factor of many variables:
But you can definitely analyze the program flow to help you arrive at an answer:
Imploding in PHP:
Pros:
1234567890
is 10 bytes ASCII, 4 bytes as a 32-bit integer)Imploding in MySQL:
Pros:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With