1

I am looking for a way to convert the result of a query to a string. The query can be

DESC entries;

or

SHOW COLUMNS FROM entires;

For example, both yield the same result if I execute them in the CLI which is:

+---------+-------------+------+-----+---------+----------------+
| Field   | Type        | Null | Key | Default | Extra          |
+---------+-------------+------+-----+---------+----------------+
| id      | int(11)     | NO   | PRI | NULL    | auto_increment |
| name    | varchar(45) | YES  |     | NULL    |                |
| content | text        | YES  |     | NULL    |                |
| time    | int(11)     | YES  |     | NULL    |                |
+---------+-------------+------+-----+---------+----------------+

However, I need this table as one string. It is NOT an option for me to get his information out of the information_schema.columns table because this information is not present there. It is further necessary to achieve this on the same query. Using PHP or another language is also not an option.

I have tried various things but none of them have been successful so far. These queries all resulted in an error:

SELECT group_concat(Field) FROM (SHOW COLUMNS FROM entries);
SELECT group_concat(SHOW COLUMNS FROM entries);
SELECT group_concat(SHOW COLUMNS FROM entries LIMIT 1);
SELECT Field from (SHOW COLUMNS FROM entries);
SELECT 1 from (SHOW COLUMNS FROM entries);
SELECT group_concat(SHOW COLUMNS FROM entries);
SELECT group_concat(SHOW COLUMNS) FROM entries;

I have tried the same with desc entries; but with the same result.

I always get an error like this:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that
    corresponds to your MySQL server version for the right syntax to use near 'show columns
    from entries)' at line 1

Neither Google nor the manual could tell me how to achieve this, maybe I was looking for the wrong phrases. Any help is highly appreciated.

JRsz
  • 2,891
  • 4
  • 28
  • 44
  • This [post](https://stackoverflow.com/a/22009889/7004388) might help you. – coderpc May 25 '17 at 22:40
  • I dont see how tbh. That would not help me since I do not have strings in my query and the table name is valid without the backtick – JRsz May 25 '17 at 22:43
  • I can't see any other way than `information_schema` tbh, `desc` is not the same as select and hence, you can't wrap it into `SELECT`. – Darshan Mehta May 25 '17 at 22:46
  • there must be a way to extract this information :/ – JRsz May 26 '17 at 07:49

0 Answers0