Re: Database abstraction?

From: Date: Wed, 16 Apr 2008 14:55:14 +0000
Subject: Re: Database abstraction?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-273074@lists.php.net to get a copy of this message
On 4/16/08, Jason Pruim <japruim@raoset.com> wrote: > > Hi Everyone! > > I'm back with yet another question.... But getting closer to sounding like > I know what I'm talking about and that's all thanks to all of you. A free > beer (Or beverage of choice)* for everyone who has helped me over the years! > > Here's my question... I have a program, where I want to take out the field > names in a database table and display them... In other words instead of > writing: > $Query ="SELECT First, Last, Middle, Add1 FROM mytable order by $order"; > > I want to write something more like: > $Query ="SELECT $FIELDNAMES FROM mytable order by $order"; > > So I need to know how to get the field names from the database so that I > can populate $FIELDNAMES. I played a little bit and it looks like I might be > able to get what I want by doing 2 queries... > > $QueryFieldNames = "DESCRIBE $table"; > > And then some sort of a foreach or maybe a while to populate $FIELDNAMES? > Maybe an array so I could do $FIELDNAMES['First'] if I needed to later. > > then I can use my SELECT $FIELDNAMES FROM $table order by $order query to > do my query... mysql_list_fileds came to mind, but this link states mysql_list_fileds is deprecated and suggests using mysql_query("show columns from table"). http://us.php.net/manual/en/function.mysql-list-fields.php -- > > -David. > > When the power of love > overcomes the love of power, > the world will know peace. > > -Jimi Hendrix

« previous php.general (#273074) next »