Re: Database abstraction?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, 16 Apr 2008 10:43:15 -0400, Jason Pruim <japruim@xxxxxxxxxx> 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...
>
> Am I on the right path? Way off base? Not even in the ball park?
>
> Hopefully it makes sense... Cause it's right on the edge of my
> knowledge so I'm not totally sure how to ask it right yet :)

PDO syntax:

$result = $db->query("SELECT * FROM mytable ORDER BY ". $order_field);
$result->setFetchMode(PDO::FETCH_ASSOC);
foreach ($result as $record) {
  print "OMG, I have an associative array!";
}

http://us3.php.net/manual/en/pdostatement.fetch.php

> *Assuming wife 2.0.198BETA approves...

Any program that is interfering with a vital system operation like that should
be uninstalled until it is fixed.

--Larry Garfield


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux