#StackBounty: #php #mysql MySQL output not formatted when executed through php

Bounty: 50

I’m trying to get formatted output from mysql as it normally shows when executed from a shell. This is discussed here and here, but it’s not working for me.

When I run this in my shell for instance:

mysql -e "select language_id, name, image from `language`;" my_database

I get the expected output:

+-------------+-----------+--------+
| language_id | name      | image  |
+-------------+-----------+--------+
|           1 | English   | gb.png |
|           2 | Français  | fr.png |
+-------------+-----------+--------+

But when I do the same thing from the php cli:

passthru('mysql -e "select language_id, name, image from `language`;" my_database');

It comes out with no formatting:

language_id name    image
1   English gb.png
2   Français    fr.png

I’ve tried passthru, system, exec, and shell_exec but all return the same unformatted output. Why is the output different when run from php?


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.