let there is a table user(user_id int,user_name varchar)
I want to get all data along with its datatype in a single query in mysql.
select * from user;
describe user;
but these are two different query. I want the result in a single query.I want to get the result in php so that i can convert in a json i.e. json_encode;
Actually I want to get the result in the following format... only 1 row is available
[
{"attr_name":"user_id","value","5","attr-type":"int"},
{"attr_name":"user_name","value","6","attr-type":"varchar"}
]
If you are using mysqli - then after running doing a mysqli_prepare
with your select * statement, you can call
$result = $stmt->result_metadata();
To get a description of each field. If using PDO - use getColumnMeta
in something like
$select = $DB->query('SELECT * FROM table');
$meta = $select->getColumnMeta(0);