php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #66696 Slight error in description
Submitted: 2014-02-12 07:10 UTC Modified: 2016-06-14 15:49 UTC
From: php_bugs at multiwebinc dot com Assigned: cmb (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.4.25 OS: Debian
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: php_bugs at multiwebinc dot com
New email:
PHP Version: OS:

 

 [2014-02-12 07:10 UTC] 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'.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-07-23 20:47 UTC] chealer at gmail dot com
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***.
 [2015-07-23 23:04 UTC] php_bugs at multiwebinc dot com
I guess whoever fixed it didn't notice this bug report. I don't remember the password, so whoever has access please close this. It is fixed.
 [2016-06-14 15:49 UTC] cmb@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: cmb
 [2016-06-14 15:49 UTC] cmb@php.net
Yes, apparently this ticket has been overlooked.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Wed Oct 07 13:00:02 2026 UTC