# PDO_DBLIB type handling

- Thread: https://externals.io/message/83328
- Original archive: https://news-web.php.net/php.internals/83328
- Started by Adam Baratz on 2015-02-20T17:22:40+00:00
- Messages: 9
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #83328 — Adam Baratz — 2015-02-20T17:22:40+00:00

URL: https://externals.io/message/83328#83328

Hi,

This driver returns all column data as a string, regardless of how it's
represented in the DB. I created a patch for my own use that syncs up the
type handling with the behavior of the MSSQL extension. This seems like it
would be of general use. Does anyone have any feedback before I put
together an RFC? My main question would be whether people would rather have
this be the default/only behavior, or whether it should be opted into
via PDO::ATTR_STRINGIFY_FETCHES.

Thanks,
Adam

---

## #83438 — Yasuo Ohgaki — 2015-02-21T22:12:06+00:00

URL: https://externals.io/message/83328#83438 · In reply to: #83328

Hi Adam,



> This driver returns all column data as a string, regardless of how it's
> represented in the DB. I created a patch for my own use that syncs up the
> type handling with the behavior of the MSSQL extension. This seems like it
> would be of general use. Does anyone have any feedback before I put
> together an RFC? My main question would be whether people would rather have
> this be the default/only behavior, or whether it should be opted into
> via PDO::ATTR_STRINGIFY_FETCHES.
>

Databases return "string" data to return correct data in DB.
Most obvious is "NUMERIC" data type. NUMERIC has any precision.
We may have 128 bit INT in near future also.

So it should return string by default, PHP may convert  types into
PHP native types optionally. Not the other way around. IMHO.

Regards,

--
Yasuo Ohgaki
yohgaki@ohgaki.net

---

## #83447 — Lester Caine — 2015-02-21T23:26:01+00:00

URL: https://externals.io/message/83328#83447 · In reply to: #83438

> > […]
> Databases return "string" data to return correct data in DB.
> Most obvious is "NUMERIC" data type. NUMERIC has any precision.
> We may have 128 bit INT in near future also.
> 
> So it should return string by default, PHP may convert  types into
> PHP native types optionally. Not the other way around. IMHO.

It is probably worth pointing to date and time types as a good example
of where there is not practical to take a binary view of the data since
there are a number of differences between databases, and up until now it
has only been safe to use 32bit numbers directly in PHP which is
additional reasons for keeping to a string base.

( Since all of my material is managed via databases it is also why I am
normally using 'stringy ints'! )

-- 
Lester Caine - G8HFL
-----------------------------
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk
Rainbow Digital Media - http://rainbowdigitalmedia.co.uk

---

## #83467 — Matteo Beccati — 2015-02-22T10:45:32+00:00

URL: https://externals.io/message/83328#83467 · In reply to: #83438

> Hi Adam,
>
> 
>
> > […]
>
> Databases return "string" data to return correct data in DB.
> Most obvious is "NUMERIC" data type. NUMERIC has any precision.
> We may have 128 bit INT in near future also.
>
> So it should return string by default, PHP may convert  types into
> PHP native types optionally. Not the other way around. IMHO.

The default behaviour of mysql/pgsql drivers is to convert to the 
matching PHP type, if possible. That can be turned off via 
PDO::ATTR_STRINGIFY_FETCHES => true.

If PDO_DBLIB doesn't behave like that, I'd say it's a bug that needs to 
be fixed, but possibly only applied to a major/minor release due to the 
BC break.


Cheers
-- 
Matteo Beccati

Development & Consulting - http://www.beccati.com/

---

## #83486 — Yasuo Ohgaki — 2015-02-22T21:02:40+00:00

URL: https://externals.io/message/83328#83486 · In reply to: #83467

Hi Matteo,



> The default behaviour of mysql/pgsql drivers is to convert to the matching
> PHP type, if possible. That can be turned off via
> PDO::ATTR_STRINGIFY_FETCHES => true.
>
> If PDO_DBLIB doesn't behave like that, I'd say it's a bug that needs to be
> fixed, but possibly only applied to a major/minor release due to the BC
> break.
>

Please write up RFC now. It's the time :)

Regards,

--
Yasuo Ohgaki
yohgaki@ohgaki.net

---

## #83556 — Matteo Beccati — 2015-02-23T09:42:52+00:00

URL: https://externals.io/message/83328#83556 · In reply to: #83486

> Hi Matteo,
>
> 
>
> > […]
>
> Please write up RFC now. It's the time :)

I'm actually saying that we don't need yet another RFC to fix bugs ;)


Cheers
-- 
Matteo Beccati

Development & Consulting - http://www.beccati.com/

---

## #83602 — Adam Baratz — 2015-02-23T20:12:27+00:00

URL: https://externals.io/message/83328#83602 · In reply to: #83556

Makes sense to me. (I'm new at how this community works.) Should I include
a patch with the feature request ticket? Should I be working against master?



> 
>
> > […]
>
> I'm actually saying that we don't need yet another RFC to fix bugs ;)
>
>
>
> Cheers
> --
> Matteo Beccati
>
> Development & Consulting - http://www.beccati.com/

---

## #83604 — Matteo Beccati — 2015-02-23T20:19:32+00:00

URL: https://externals.io/message/83328#83604 · In reply to: #83602

> Makes sense to me. (I'm new at how this community works.) Should I include
> a patch with the feature request ticket? Should I be working against master?

I'd say you should start by submitting a bug report (if there isn't one 
already). Then a pull request on github would probably be easier for 
everyone.

Even though the old behaviour should be possible by setting 
PDO::ATTR_STRINGIFY_FETCHES to true, it is is a fairly big behaviour 
change for PDO_DBLIB, so master-only would be your best bet.

My .02$


Cheers
-- 
Matteo Beccati

Development & Consulting - http://www.beccati.com/

---

## #83925 — Adam Baratz — 2015-02-26T20:33:37+00:00

URL: https://externals.io/message/83328#83925 · In reply to: #83604

Thanks, I posted a pull request against v5.6.6:
https://github.com/php/php-src/pull/1122

If this goes through, I can do a separate patch against master. (This ext
has changed very little over time so it would be largely the same.)



> 
>
> > […]
>
> I'd say you should start by submitting a bug report (if there isn't one
> already). Then a pull request on github would probably be easier for
> everyone.
>
> Even though the old behaviour should be possible by setting
> PDO::ATTR_STRINGIFY_FETCHES to true, it is is a fairly big behaviour change
> for PDO_DBLIB, so master-only would be your best bet.
>
> My .02$
>
>
>
> Cheers
> --
> Matteo Beccati
>
> Development & Consulting - http://www.beccati.com/
