Doc #66696 [Com]: Slight error in description
| From: | chealer at gmail dot com | Date: | Thu, 23 Jul 2015 20:47:05 +0000 |
| Subject: | Doc #66696 [Com]: Slight error in description | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-12546@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=66696&edit=1
ID: 66696
Comment by: chealer at gmail dot com
Reported by: php_bugs at multiwebinc dot com
Summary: Slight error in description
Status: Open
Type: Documentation Problem
Package: Documentation problem
Operating System: Debian
PHP Version: 5.4.25
Block user comment: N
Private report: N
New Comment:
The manual does say:
You cannot use a named parameter marker of the same name more than once in a prepared statement,
***unless emulation mode is on***.
Previous Comments:
------------------------------------------------------------------------
[2014-02-12 07:10:11] php_bugs at multiwebinc dot com
Description:
------------
---
From manual page: http://www.php.net/pdo.prepare
---
The manual says "You cannot use a named parameter marker of the same name twice in a prepared
statement", however this is not completely true. If PDO::ATTR_EMULATE_PREPARES is set to true,
you *can* re-use the same parameter marker more than once. I'm not sure if this is a bug with
the docs or a bug with PDO.
Test script:
---------------
The following worked just fine for me by default (I'm assuming prepared statements were being
emulated):
<?php
$stmt = $dbh->prepare("
SELECT tour_photo_id, name,
desc FROM
(
SELECT tour_photo_id, tours_i18n.name, desc FROM
tour_photos
LEFT JOIN tour_photos_i18n ON tour_photos.id = tour_photos_i18n.tour_photo_id
LEFT JOIN tours ON tour_photos.tour_id = tours.id
LEFT JOIN tours_i18n ON tours.id = tours_i18n.tour_id
WHERE tour_photos.id IN (".implode(',', $banner_img_ids).")
AND tours_i18n. lang_id = :lang_id
AND tour_photos_i18n.lang_id = :lang_id
UNION
SELECT tour_photo_id, tours_i18n.name, desc FROM
tour_photos
LEFT JOIN tour_photos_i18n ON tour_photos.id = tour_photos_i18n.tour_photo_id
LEFT JOIN tours ON tour_photos.tour_id = tours.id
LEFT JOIN tours_i18n ON tours.id = tours_i18n.tour_id
WHERE tour_photos.id IN (".implode(',', $banner_img_ids).")
AND tours_i18n. lang_id = :en_lang_id
AND tour_photos_i18n.lang_id = :en_lang_id
) a
GROUP BY tour_photo_id
ORDER BY FIELD(tour_photo_id, ".implode(',', $banner_img_ids).")
");
$stmt->bindValue(':lang_id', $lang_id);
$stmt->bindValue(':en_lang_id', $en_lang_id);
$stmt->execute();
?>
Note, both :lang_id and :en_lang_id are used more than once.
However when I set PDO::ATTR_EMULATE_PREPARES to false, I get 'SQLSTATE[HY093]: Invalid
parameter number'.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=66696&edit=1