dongpi9480 2017-05-12 06:00
浏览 401

如何在mysql的单个查询中获取所有数据及其数据类型?

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"}
]
  • 写回答

1条回答 默认 最新

  • doulun1915 2017-05-12 06:22
    关注

    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);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记