我正在寻找一种方法来获取 mysql 查询的结果集,该查询类似于 ActiveRecord::Base.connection.select_rows 的输出,但也包括结果的列名称作为第一个元素。
例如:
ActiveRecord::Base.connection.select_rows_with_fields("SELECT id,name FROM users")
=> [["id", "name"], ["1","amy"],["2","bob"],["3","cam"]]
我正在寻找一种方法来获取 mysql 查询的结果集,该查询类似于 ActiveRecord::Base.connection.select_rows 的输出,但也包括结果的列名称作为第一个元素。
例如:
ActiveRecord::Base.connection.select_rows_with_fields("SELECT id,name FROM users")
=> [["id", "name"], ["1","amy"],["2","bob"],["3","cam"]]