For Programmers: Free Programming Magazines  


Home > Archive > PHP PEAR Questions and Answers > August 2004 > [DB] returning typed data when fetching rows









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author [DB] returning typed data when fetching rows
Guillaume Cocatre-Zilgien

2004-08-05, 8:56 pm

Hello,

I have been writing a custom class for using a PostgreSQL database,
while looking at the DB classes to see if I could take advantage of them.

Although I plan to use them in the near future, there is at least one
feature that I find missing from them: I would like to have strongly
typed data when fetching rows. I expect to get PHP integers, arrays,
booleans instead of strings ('4', '{"foo","bar",{"this is foobar"}}',
't'...).

So I have written some methods that:
1) collect information about fields and caches them (feature
available in PEAR classes)
2) convert a PHP value into an SQL string (supports PG arrays)
3) convert a value returned by the database (string) into a typed value
(supports PG arrays as well)

I think this should be implemented directly in PHP's extensions (in
pg_fetch_row(), for instance), but since it isn't, I was wondering if
such features would be welcome in PEAR's DB classes - not just for
PostgreSQL, but also the other DB's implementations).

If they are welcome, to which class(es) should they be added? DB_Table
supports some type casting, but not for fetching rows, and it doesn't
support arrays. Perhaps DB_pgsql and the likes?

Please let me know what you think.
Michael Wallner

2004-08-06, 8:55 am

Hi Guillaume Cocatre-Zilgien, you wrote:
> Hello,
>
> I have been writing a custom class for using a PostgreSQL database,
> while looking at the DB classes to see if I could take advantage of them.
>
> Although I plan to use them in the near future, there is at least one
> feature that I find missing from them: I would like to have strongly
> typed data when fetching rows. I expect to get PHP integers, arrays,
> booleans instead of strings ('4', '{"foo","bar",{"this is foobar"}}',
> 't'...).
>
> So I have written some methods that:
> 1) collect information about fields and caches them (feature
> available in PEAR classes)
> 2) convert a PHP value into an SQL string (supports PG arrays)
> 3) convert a value returned by the database (string) into a typed value
> (supports PG arrays as well)
>
> I think this should be implemented directly in PHP's extensions (in
> pg_fetch_row(), for instance), but since it isn't, I was wondering if
> such features would be welcome in PEAR's DB classes - not just for
> PostgreSQL, but also the other DB's implementations).
>
> If they are welcome, to which class(es) should they be added? DB_Table
> supports some type casting, but not for fetching rows, and it doesn't
> support arrays. Perhaps DB_pgsql and the likes?
>
> Please let me know what you think.


Have a look at MDB[2]

Regards,
--
Michael - < mike(@)php.net >

Guillaume Cocatre-Zilgien

2004-08-06, 8:55 am

Michael Wallner wrote:

> Have a look at MDB[2]


Sorry, I accidently crossposted to php.pear.dev. I already replied to
this on that NG. Please fu2 there.

Guillaume
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com