Re: [DB] Suggestion for field types
| From: | Hans Lellelid | Date: | Thu, 08 Jan 2004 16:08:28 +0000 |
| Subject: | Re: [DB] Suggestion for field types | ||
| References: | 1 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-24894@lists.php.net to get a copy of this message | ||
Peter wrote:
Attachment: [application/x-pkcs7-signature] S/MIME Cryptographic Signature smime.p7s
Hi all. Is there a mechanism in pear DB to ask about the generic field type? Eg. the following would be useful: ... $i = ... column number of result if ($result->isNumber($i)) ... code to right justify result if ($result->isChar($i)) ... code to quote/do case conversion etc. ... This would avoid having to worry about strange types like bpchar, SQLSMINT, int2. My feeling is the native types should in fact be entirely invisible via PEAR - that's what the native API's are for. Well, I think the bigger issue here is the fact that there is no resultset metadata available using the native drivers in PHP. There are a number of abstraction layers that do have abstracted db types -- MDB2 (i believe), ADOdb, Creole -- but it's not available as part of a resultset: you would have to perform an additional query to get metadata for the table in order to know which columns were numeric, data, string, etc.Obviously one solution is just to use functions like is_numeric() and strtotime() which can help you guess at the underlying datatypes. Your best solution, however, is probably to use a more managed data-access layer. Paul mentions DB_Table has this support -- if so, that may be the perfect package for your needs. DB_DataObject also has knowledge of underlying datatypes -- not sure if it provides an API for easily returning that info, though. Propel is another (non-PEAR) solution for object persistence; Propel builds tablemap classes that provide a quick (static, no queries) way to get detailed information about table columns (and indexes, primary key, foreign keys, etc.). Cheers, Hans
Attachment: [application/x-pkcs7-signature] S/MIME Cryptographic Signature smime.p7s