سؤال

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?

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top