Question

I have a PHP application which allows its trusted users to query MySQL by typing the query into a textbox and then submitting it to the webserver. The application doesn't and shouldn't know what the query does and therefore isn't able to properly format the response from the MySQL, that would require analysing the query. How would I go about getting a plain text (unformatted) response from MySQL like when you're querying via the console user interface.

Was it helpful?

Solution

Client software packages presenting the illusion of "plain text" from query result sets actually do a bunch of formatting work to render the result that way.

They rely on the fact that the RDMS returns column descriptors (metadata) with the data. In PHP's mysqli interface, for example, the fetch_fields method retrieves the column descriptors. Each column has a bunch of items describing it, including the maximum character width it needs.

To render a result set as text, you need to use this metadata to format it.

See here for an explanation. http://www.php.net/manual/en/mysqli-result.fetch-fields.php

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top