From: php-list@yahoogroups.com [mailto:[EMAIL PROTECTED] On Behalf
Of James Keeline
Sent: Sunday, December 30, 2007 12:53 PM
To: php-list@yahoogroups.com
Subject: Re: [php-list] PHP/MySQL question
--- Daniel Israel <HYPERLINK "mailto:dan%40ebji.org"[EMAIL PROTECTED]> wrote:
> 1. When I do a MySQL query, is there a way to get the returned columns in
> the query without fetching a row? Currently, what I'm doing is fetching a
> row of data and getting the keys from the array. I'd like to do it without
> fetching the row. Is this possible?
>
> 2. If #1 above is indeed possible, is this only possible when I get
returned
> rows or can I do it when there are no matching rows in the query?
>
> Thanks for any help!
>
> -D. Israel
If you have at least one row of data you could get the column names through
a
query like this:
SELECT * FROM table_name LIMIT 1;
However, in many applications this may not be practical because the table
may
be empty. You could use MySQL to describe the table for you and parse the
results you want:
DESC table_name;
There are some MySQL functions in PHP which can be used for this purpose but
in
looking at the examples on HYPERLINK
"http://php.net/mysql_fetch_field"http://php.net/mysql_fetch_field they seem
more
complex than is necessary to achieve the goal.
James
Or, you could run a query against information_schema. That is, depending on
the version of MySQL that youre working with (5.02 or later).
For example:
select column_name from information_schema.columns where table_name =
your_table_name_here
You might have to filter on table_schema as well if you have multiple
schemas.
Jason
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.516 / Virus Database: 269.17.12/1202 - Release Date: 12/29/2007
1:27 PM
[Non-text portions of this message have been removed]
Community email addresses:
Post message: php-list@yahoogroups.com
Subscribe: [EMAIL PROTECTED]
Unsubscribe: [EMAIL PROTECTED]
List owner: [EMAIL PROTECTED]
Shortcut URL to this page:
http://groups.yahoo.com/group/php-list
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/php-list/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/php-list/join
(Yahoo! ID required)
<*> To change settings via email:
mailto:[EMAIL PROTECTED]
mailto:[EMAIL PROTECTED]
<*> To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/