Hm yes, sounds plausible. But it's not an issue in my application. From
my experience, integers on PHP 64 bit are also 64 bit wide, which is way
more than I expect to see. And the IEEE double type should actually be
standard. I'm not sure if SQLite supports anything beyond that.
My columns are statically typed, so conversion would be doable. But why
would I if there's a simple solution to avoid that hack. I'll try to
remember that quirks in my next PDO application targeting other DBMS
(which happens very rarely).
-Yves
-------- Ursprüngliche Nachricht --------
Von: Aziz Saleh <azizsaleh@xxxxxxxxx>
Gesendet: Dienstag, 4. April 2023, 22:32 MESZ
Betreff: PDO returns all data as strings?!
One of the reasons why they are returned as string (and I think the main
reason) is that PHP has a limit to ints/doubles that is far much lower
than SQL. If they return int many people would have issues.
I would recommend that you just create your own "passthrough" class that
will set the type based on the schema (or list of columns you have in a
config), this would be harder if those columns are dynamic though.
On Tue, Apr 4, 2023 at 4:26 PM Yves Goergen <nospam.list@xxxxxxxxxxxxxxx
<mailto:nospam.list@xxxxxxxxxxxxxxx>> wrote:
No, that doesn't change anything.
Meanwhile I've tried out the SQLite3 classes and found that their
API is
very similar. I had almost no work adapting my code. These classes work
fine and return the real data type, not a converted view of it. And it
even allows resolving the SQL statement including bound parameter
values
which is helpful for debugging. I'll keep that.
-Yves
-------- Ursprüngliche Nachricht --------
Von: Aziz Saleh <azizsaleh@xxxxxxxxx <mailto:azizsaleh@xxxxxxxxx>>
Gesendet: Montag, 3. April 2023, 21:59 MESZ
Betreff: PDO returns all data as strings?!
Try setting this option and see if it helps:
PDO::ATTR_STRINGIFY_FETCHES => false
On Mon, Apr 3, 2023 at 3:31 PM Yves Goergen via php-general
<php-general@xxxxxxxxxxxxx <mailto:php-general@xxxxxxxxxxxxx>
<mailto:php-general@xxxxxxxxxxxxx
<mailto:php-general@xxxxxxxxxxxxx>>> wrote:
Hello,
I just noticed a weird behaviour of PDO for my SQLite
database and
found
a hint online. Just wanted to check here.
Is it correct that PDO will return all queried values from the
fetch
method as string, no matter the actual data type? I couldn't
find that
notice by glancing over the documentation. (Such an unexpected
note
should be very well visible.)
If that's the case, can it be fixed immediately (for PHP 7.4 and
later)?
Or what alternatives to PDO could I use for SQLite only? I need
prepared
statements and parameter binding.
I know how SQLite handles data types, and it includes
remembering the
type that was given to it. If PHP/PDO then destroys it, it's
of very
limited use.
My code looks like this:
$ps = $this->connection->prepare('select * from table');
$ps->execute();
$record = $ps->fetch(PDO::FETCH_ASSOC);
-Yves