RE: [PEAR] [MDB] About types conversions
| From: | Lukas Smith | Date: | Sat, 30 Aug 2003 15:22:39 +0000 |
| Subject: | RE: [PEAR] [MDB] About types conversions | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-7500@lists.php.net to get a copy of this message | ||
> From: Thierry Bothorel [mailto:thierry.bo@netcourrier.com]
> Sent: Saturday, August 30, 2003 4:56 PM
> 1/ If I want to insert the current DateTime in a timestamp field, I
> thought
> that I just could use in my sql statement :
>
> $sql = "INSERT INTO mytable ( field1, timestamp, field2)
> VALUES (value1, '" . MDB_Date::mdbNow() . "', value2)";
>
> so that the datetime is already in the good MDB timestamp type. But in
>
http://www.php-mag.net/itr/online_artikel/psecom,id,283,nodeid,114.html
> ('Write once - run anywhere'), I see that a unix time variable is
first
> converted to MDB time stamp with 'unix2Mdbstamp' and then again with
> 'getTimestampValue'.
That is correct.
Basically MDB defines native formats for each datatype. This is the
format you need to insert into the get*Type methods and this is the
format that you receive back when fetching if you specify the types of
the result columns.
mdbNow() will give you the current time in the MDB format. Just as any
other date in the MDB format it may need to be converted into a native
representation.
> Does it mean that an MDB timestamp is not sufficient to provide each
DBMS
> driver the proper value and instead I had to write my sql statement
like
> this ? :
>
> $sql = "INSERT INTO mytable ( field1, timestamp, field2)
> VALUES (value1, '" . getTimestampValue(MDB_Date::mdbNow()) . "',
value2)";
>
> /2- In MDB tutorial, it is said that "text and integer result data do
not
> need to be converted" in a result set. But in the same PHP magazine
> article
> above it is said that only integer does not need to be converted, but
we
> are
> adviced to convert all types ?
Well as I tried to make clear in the magazin article:
Converting is optional. Some types usually don't need any converting and
integers and text are those. For them you may simply pass "null" as the
type an no conversion is done. Of course even if you pass the type no
conversion is actually done for most drivers (actually all current
drivers don't change much .. for integers they do an intval atm .. which
I am not sure yet is smart as this might be an issue for really high
values stored in a BIGINT field). However the world is weird and so are
the RDBMS developers. Maybe some RDBMS developer might return data in a
weird way that a conversion maybe needed; seems somewhat unlikely
however.
Regards,
Lukas