# PDO statement execute enhancement

- Thread: https://externals.io/message/25254
- Original archive: https://news-web.php.net/php.internals/25254
- Started by Marian Kostadinov on 2006-08-09T08:25:41+00:00
- Messages: 7
- 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

---

## #25254 — Marian Kostadinov — 2006-08-09T08:25:41+00:00

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

I have a suggestion that is related a little to my bug report #38394 (
http://bugs.php.net/bug.php?id=38394).

It's about the execution of a prepared statement.
Let's say we have a prepared statement for

UPDATE table SET field1 = :field1, field2 = :field3 WHERE id = :id

in order to execute it we have something like this:
$data = array ('id' => 3, 'field1' => 'value1', 'field2' => 'value2');
$stmt->execute ($data);

But I think that it is so common to have things like this
$data = array ('id' => 3, 'field1' => 'value1', 'field2' => 'value2',
'field3' => 'value3', 'field4' => 'value4');
$stmt->execute ($data);

But that is not executed because we have some additional key/value pairs.
So the idea is to allow this. Also I suggest we allow using object along
with an array. This is a common situation also.

But I have to ask you about the C implementation because it may need a lot
of rewriting about this but if it is easy, it think it may be good to be
done.

---

## #25255 — Derick Rethans — 2006-08-09T08:34:04+00:00

URL: https://externals.io/message/25254#25255 · In reply to: #25254

> I have a suggestion that is related a little to my bug report #38394 (
> http://bugs.php.net/bug.php?id=38394).
> 
> It's about the execution of a prepared statement.
> Let's say we have a prepared statement for
> 
> UPDATE table SET field1 = :field1, field2 = :field3 WHERE id = :id
> 
> in order to execute it we have something like this:
> $data = array ('id' => 3, 'field1' => 'value1', 'field2' => 'value2');
> $stmt->execute ($data);
> 
> But I think that it is so common to have things like this
> $data = array ('id' => 3, 'field1' => 'value1', 'field2' => 'value2',
> 'field3' => 'value3', 'field4' => 'value4');
> $stmt->execute ($data);
> 
> But that is not executed because we have some additional key/value pairs.
> So the idea is to allow this. Also I suggest we allow using object along
> with an array. This is a common situation also.

Actually, it is dependent on the driver what happens here, which is not 
at all documented either. However, it would be nice if this indeed would 
work.

Derick
-- 
Derick Rethans
http://derickrethans.nl | http://ez.no | http://xdebug.org

---

## #25256 — Michael Wallner — 2006-08-09T08:44:45+00:00

URL: https://externals.io/message/25254#25256 · In reply to: #25255

Derick Rethans wrote:
> 

> > […]
> 
> Actually, it is dependent on the driver what happens here, which is not 
> at all documented either. However, it would be nice if this indeed would 
> work.

I second this.

Regards,
-- 
Michael

---

## #25259 — Lukas Smith — 2006-08-09T10:19:17+00:00

URL: https://externals.io/message/25254#25259 · In reply to: #25256

Michael Wallner wrote:

> Derick Rethans wrote:
> > […]
> 
> > […]
> 
> I second this.

Being able to use Objects probably only makes sense if we ignore 
additional keys that have not been defined as placeholders. I do not 
think that this change makes sense though.

regards,
Lukas

---

## #25260 — Marian Kostadinov — 2006-08-09T11:44:55+00:00

URL: https://externals.io/message/25254#25260 · In reply to: #25259

Yes, that's my idea - to ignore keys that are not defined as placeholder.
And not only for objects but for arrays also.

2006/8/9, Lukas Smith <lsmith@php.net>:
>
> Michael Wallner wrote:
>
> > […]
> pairs.
> > […]
> along
> > […]
> would
> > […]
>
> Being able to use Objects probably only makes sense if we ignore
> additional keys that have not been defined as placeholders. I do not
> think that this change makes sense though.
>
> regards,
> Lukas

---

## #25261 — Lukas Smith — 2006-08-09T11:51:09+00:00

URL: https://externals.io/message/25254#25261 · In reply to: #25260

Marian Kostadinov wrote:

> Yes, that's my idea - to ignore keys that are not defined as placeholder.
> And not only for objects but for arrays also.

I do not know the implementation in PDO, but the implementation I made 
in MDB2 only tries to parse the placeholders if it has to emulate or 
detects that a placeholder type is used that needs to be rewritten for 
the given RDBMS. If PDO has a similar implementation it would mean now 
that PDO always has to parse the entire query to determine which keys to 
ignore. I feel this is suboptimal and therefore I would be opposed to 
this change.

regards,
Lukas

---

## #25278 — Marian Kostadinov — 2006-08-10T10:40:05+00:00

URL: https://externals.io/message/25254#25278 · In reply to: #25261

This code here

http://lxr.php.net/source/php-src/ext/pdo/pdo_stmt.c#301

is maybe the point where a solution can be provided checking for

param <http://lxr.php.net/ident?i=param>->paramno == -1 is enough to
detect an incorrect parameter and silently
ignore it or emit a notice.





2006/8/9, Lukas Smith <lsmith@php.net>:
>
> Marian Kostadinov wrote:
>
> > […]
> placeholder.
> > […]
>
> I do not know the implementation in PDO, but the implementation I made
> in MDB2 only tries to parse the placeholders if it has to emulate or
> detects that a placeholder type is used that needs to be rewritten for
> the given RDBMS. If PDO has a similar implementation it would mean now
> that PDO always has to parse the entire query to determine which keys to
> ignore. I feel this is suboptimal and therefore I would be opposed to
> this change.
>
> regards,
> Lukas
