2

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 tables with various column names aliased.

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

clang1234
  • 1,704
  • 2
  • 16
  • 28

3 Answers3

2

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.

Jan Fabry
  • 7,221
  • 2
  • 36
  • 41
  • That's exactly what I needed. Thanks so much. That with a combination of mysql_fetch_fields and a for loop gives me everything I need. – clang1234 Jan 25 '11 at 19:49
1
SHOW COLUMNS FROM `table_name`;
dqhendricks
  • 19,030
  • 11
  • 50
  • 83
  • Unfortunately I'm not simply processing a query on one table. The query consists of multiple tables joined together with various columns aliased. I'll edit the op with this clarification. – clang1234 Jan 24 '11 at 18:03
0

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.

vvm
  • 136
  • 2