# PDO: Disable emulated prepares by default?

- Thread: https://externals.io/message/88018
- Original archive: https://news-web.php.net/php.internals/88018
- Started by Scott Arciszewski on 2015-09-03T04:14:13+00:00
- Messages: 10
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #88018 — Scott Arciszewski — 2015-09-03T04:14:13+00:00

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

Inspired by http://stackoverflow.com/a/12202218/2224584

Can we (in either PHP 7.0 or in PHP 7.1) turn emulated prepared
statements off by default, and still allow developers to turn it on if
they really want them?

For now my code works around this design decision, but not everybody
is cognizant of this behavior.

Scott Arciszewski
Chief Development Officer
Paragon Initiative Enterprises <https://paragonie.com

---

## #88021 — Ferenc Kovacs — 2015-09-03T06:33:45+00:00

URL: https://externals.io/message/88018#88021 · In reply to: #88018

2015. szept. 3. 6:14 ezt írta ("Scott Arciszewski" <scott@paragonie.com>):
>
> Inspired by http://stackoverflow.com/a/12202218/2224584
>
> Can we (in either PHP 7.0 or in PHP 7.1) turn emulated prepared
> statements off by default, and still allow developers to turn it on if
> they really want them?
>
> For now my code works around this design decision, but not everybody
> is cognizant of this behavior.
>
> Scott Arciszewski
> Chief Development Officer
> Paragon Initiative Enterprises <https://paragonie.com>
>
> --
> 
> 
>

Last time we discussed this it was Anthony who proposed the change and
Rasmus shed some light on why did we have the emulation in the first place.
We can have change the default but we should have an RFC clearly stating
the impact (an additional network roundtrip and the native prepares being
less flexible vs. better security and performance gain in case of executing
the same prepared query multiple times)

---

## #88022 — Scott Arciszewski — 2015-09-03T06:36:51+00:00

URL: https://externals.io/message/88018#88022 · In reply to: #88021

>
> 2015. szept. 3. 6:14 ezt írta ("Scott Arciszewski" <scott@paragonie.com>):
> > […]
>
> Last time we discussed this it was Anthony who proposed the change and
> Rasmus shed some light on why did we have the emulation in the first place.
> We can have change the default but we should have an RFC clearly stating the
> impact (an additional network roundtrip and the native prepares being less
> flexible vs. better security and performance gain in case of executing the
> same prepared query multiple times)

Sure, and I'm fine with this being a 7.1 thing since most people work
around this anyway.

But I would like it to be changed eventually, however.

Scott Arciszewski
Chief Development Officer
Paragon Initiative Enterprises <https://paragonie.com

---

## #88024 — Kalle Sommer Nielsen — 2015-09-03T08:08:15+00:00

URL: https://externals.io/message/88018#88024 · In reply to: #88018

Hi Scott

2015-09-03 6:14 GMT+02:00 Scott Arciszewski <scott@paragonie.com>:
>
> Inspired by http://stackoverflow.com/a/12202218/2224584
>
> Can we (in either PHP 7.0 or in PHP 7.1) turn emulated prepared
> statements off by default, and still allow developers to turn it on if
> they really want them?

For 7.0, it is a no-go, and for the 7.0.x releases, I'm not so keen on
(and I'm sure Anatol can back me up on this) to introduce such a
change in behaviour in a patch release, so please target 7.1 with your
future RFC.

-- 
regards,

Kalle Sommer Nielsen
kalle@php.net

---

## #88026 — Scott Arciszewski — 2015-09-03T08:54:50+00:00

URL: https://externals.io/message/88018#88026 · In reply to: #88024

> Hi Scott
>
> 2015-09-03 6:14 GMT+02:00 Scott Arciszewski <scott@paragonie.com>:
> > […]
>
> For 7.0, it is a no-go, and for the 7.0.x releases, I'm not so keen on
> (and I'm sure Anatol can back me up on this) to introduce such a
> change in behaviour in a patch release, so please target 7.1 with your
> future RFC.
>
> --
> regards,
>
> Kalle Sommer Nielsen
> kalle@php.net

Okay, no complaint here. I just didn't know if the RM would be open to
the possibility of changing the default value in 7 (since it's a major
version change and people expect things to break).

Targeting 7.1 is fair; I'll open an RFC once I'm done with my
immediate responsibilities. :)

Scott Arciszewski
Chief Development Officer
Paragon Initiative Enterprises <https://paragonie.com

---

## #88033 — Ferenc Kovacs — 2015-09-03T11:25:19+00:00

URL: https://externals.io/message/88018#88033 · In reply to: #88021

>
> 2015. szept. 3. 6:14 ezt írta ("Scott Arciszewski" <scott@paragonie.com>):
> > […]
>
> Last time we discussed this it was Anthony who proposed the change and
> Rasmus shed some light on why did we have the emulation in the first place.
> We can have change the default but we should have an RFC clearly stating
> the impact (an additional network roundtrip and the native prepares being
> less flexible vs. better security and performance gain in case of executing
> the same prepared query multiple times)
>
for the record, here is the last discussion on the topic:
http://grokbase.com/t/php/php-internals/126fcmvv04/patch-pr-disable-attr-emulate-prepares-by-default-for-pdo-mysql


-- 
Ferenc Kovács
@Tyr43l - http://tyrael.hu

---

## #88035 — Lester Caine — 2015-09-03T12:19:12+00:00

URL: https://externals.io/message/88018#88035 · In reply to: #88033

> > […]
> for the record, here is the last discussion on the topic:
> http://grokbase.com/t/php/php-internals/126fcmvv04/patch-pr-disable-attr-emulate-prepares-by-default-for-pdo-mysql

And the information on just how each database handles the various
abstractions of place holders is still missing. While the current
proposal is framed as only effecting the pdo_mysql driver, if the
default way this is handled then affects what IS currently working
cross-database then it does have a much wider impact?

That PDO is simply not up to the job it was originally pushed to provide
is a fact and making it work just for one database begs the question
"why keep it". Testing with a generic set of code should work
identically across all supported databases and that does mean that some
level of emulation is required but currently there is no documentation
on just what does and what does not work.

-- 
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

---

## #88063 — Andrea Faulds — 2015-09-06T17:25:13+00:00

URL: https://externals.io/message/88018#88063 · In reply to: #88018

Hi Scott,

Scott Arciszewski wrote:
> Inspired by http://stackoverflow.com/a/12202218/2224584
>
> Can we (in either PHP 7.0 or in PHP 7.1) turn emulated prepared
> statements off by default, and still allow developers to turn it on if
> they really want them?
>
> For now my code works around this design decision, but not everybody
> is cognizant of this behavior.

I don't know if there's really still time to add this in PHP 7.0, but I 
think emulated prepares being switched off would be a good idea. One 
reason in particular is that this means we'd get properly typed results, 
rather than just strings, which would work better with PHP 7's new 
scalar type hints. PDO returning strings everywhere when using emulation 
was one thing I was completely unaware of until I turned on strict typing.

Cheers.
--
Andrea Faulds
http://ajf.me/

---

## #88069 — johannes@schlueters.de — 2015-09-06T23:23:01+00:00

URL: https://externals.io/message/88018#88069 · In reply to: #88063

> Hi Scott,
> 
> Scott Arciszewski wrote:
> > […]
> 
> I don't know if there's really still time to add this in PHP 7.0, but I 
> think emulated prepares being switched off would be a good idea. One 

Good enough to take the performance hit by the extra roundtrip?

> reason in particular is that this means we'd get properly typed results, 
> rather than just strings, which would work better with PHP 7's new 
> scalar type hints. PDO returning strings everywhere when using emulation 
> was one thing I was completely unaware of until I turned on strict typing.

For some definition of "properly". Large integers might still become
strings, same for decimals etc. Also if you might use other databases
than MySQL still anything might happen.

Also mind that there are subtle differences on what can be done. A bit
constructed example but in MySQL you can't prepare
   CREATE TABLE foo (id INT DEFAULT ?)
while PDO would let you do this.

johannes

---

## #88101 — Ferenc Kovacs — 2015-09-07T17:27:47+00:00

URL: https://externals.io/message/88018#88101 · In reply to: #88069

On Mon, Sep 7, 2015 at 1:23 AM, Johannes Schlüter <johannes@schlueters.de>
wrote:

> 
> > […]
>
> Good enough to take the performance hit by the extra roundtrip?
>
> > […]
> typing.
>
> For some definition of "properly". Large integers might still become
> strings, same for decimals etc. Also if you might use other databases
> than MySQL still anything might happen.
>
> Also mind that there are subtle differences on what can be done. A bit
> constructed example but in MySQL you can't prepare
>    CREATE TABLE foo (id INT DEFAULT ?)
> while PDO would let you do this.
>
> johannes
>
>
also, binding ASC/DESC for ORDER BY is a common gotcha when moving from
emulated prepares to native.


-- 
Ferenc Kovács
@Tyr43l - http://tyrael.hu
