开发者

Getting ResultSet column names

开发者 https://www.devze.com 2023-02-06 05:32 出处:网络
I\'m using Symfony 1.1 with the Propel plugin and a MySQL database. To get my results I pass my query to a Propel connection and call executeQuery().

I'm using Symfony 1.1 with the Propel plugin and a MySQL database. To get my results I pass my query to a Propel connection and call executeQuery().

I'm trying to retrieve the column names of my ResultSet when my query fetches no results. When it has results all I have to do is take the array key names. When I have no results getRow() returns false, so I can't pull any array keys.

My query consists of multiple ta开发者_Python百科bles with various column names aliased.

Is there any other way to get the column names while still using the Propel object?


The Creole drivers for MySQL use the "classic" MySQL functions, and you can do this too. With mysql_fetch_field() you can get information about a specific field, even if no rows were returned. You only need to pass the correct result resource, and you can get that via the getResource() method of your ResultSet.


SHOW COLUMNS FROM `table_name`;


If it is concrete table, then you can do as it is said above (SHOW COLUMNS FROM table_name;).

But if you have a complex query, the one solution might be to parse the string using regular expression.

0

精彩评论

暂无评论...
验证码 换一张
取 消