Req #71885 [Com]: PostgreSQL has questin mark operator. This collide with PDO placeholder

From: Date: Tue, 12 Apr 2016 12:40:27 +0000
Subject: Req #71885 [Com]: PostgreSQL has questin mark operator. This collide with PDO placeholder
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-200507@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=71885&edit=1

 ID:                 71885
 Comment by:         rasmus at mindplay dot dk
 Reported by:        miki at epoch dot co dot il
 Summary:            PostgreSQL has questin mark operator. This collide
                     with PDO placeholder
 Status:             Open
 Type:               Feature/Change Request
 Package:            PDO PgSQL
 Operating System:   NA
 PHP Version:        Irrelevant
 Block user comment: N
 Private report:     N

 New Comment:

All of the proposed solutions sound rather complex to me.

I would suggest a much simpler approach: just allow us to escape the question mark placeholder to
make PDO ignore it, e.g. as "\?" - consistent with the way it's done by virtually
every other string template facility in PHP.


Previous Comments:
------------------------------------------------------------------------
[2016-04-04 08:05:13] mbeccati@php.net

There are plenty of alternatives on the postgres side, i.e. using the underlying function, or
defining a new operator. Adapting PDO is not going to be that easy, in comparison.

------------------------------------------------------------------------
[2016-03-24 08:08:12] miki at epoch dot co dot il

PDO has its own advantages. For example the named placeholders and its general abstraction.

If only we could set the placeholder char or disable the question mark it would be perfect.

------------------------------------------------------------------------
[2016-03-24 07:38:51] yohgaki@php.net

I don't maintain PDO pgsql, but I think it cannot workaround unless introducing new place
holder. i.e. Specify meta char like "LIKE" query.

http://www.postgresql.org/docs/9.5/static/functions-matching.html

Obvious workaround is to use pgsql module. One needs native extension to use most out of PostgreSQL.

------------------------------------------------------------------------
[2016-03-24 07:20:17] miki at epoch dot co dot il

I missed rowan answer.
So I guess ATTR_EMULATE_PREPARES is irrelevant

------------------------------------------------------------------------
[2016-03-24 07:16:03] miki at epoch dot co dot il

Hi Requinx,

The following code failed:

$sql = "SELECT * FROM post WHERE locations ? :location ORDER BY locations->:location"

$pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES ,false);

$stmt = $pdo->prepare($sql); // tried this and version bellow
$stmt = $pdo->prepare($sql, [\PDO::ATTR_EMULATE_PREPARES=>false]);

$stmt->bindValue(':location', 'bar', \PDO::PARAM_STR);
$stmt->execute();

Error when ATTR_EMULATE_PREPARES is false that happen at the line of the prepare():

Warning: PDO::prepare(): SQLSTATE[HY093]: Invalid parameter number: mixed named and positional
parameters in /path/file.php on line 57

Error when ATTR_EMULATE_PREPARES is true that happen at the line of the execute():

Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: mixed named and
positional parameters in /path/file.php on line 48

Any idea?

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=71885


--
Edit this bug report at https://bugs.php.net/bug.php?id=71885&edit=1


Thread (12 messages)

« previous php.bugs (#200507) next »