php - PDO exceptions being affected by ATTR_EMULATE_PREPARES with PostgreSQL -


I have more than the number of Params to'm trying to throw exception PDO when bound number of variable query. I preffer to use the native preparation statement

If I prepare emulated ( PDO :: ATTR_EMULATE_PREPARES = & gt; The true ) Exception works fine, I tested using this code:

  $ Pdo-> Set Attribution (PDO :: ATTR_ERRMODE, PDO :: ERRMODE_EXCEPTION); $ Sql ​​= 'SELECT id my_table WHERE doc =: doc'; {$ Ps = $ Pdo-> Try ($ sql, array (PDO :: ATTR_EMULATE_PREPARES = & true;);); $ Result = $ Ps- & gt; Execute (array: (': Doctor' =>; '1234', ': name' = & gt; 'miles')); } Hold (PDO Exception $ E) {New option ('Question failed:'. $ E- & gt; GET message ()); }  

Throws:

  Fatal error: Exception with the message "Ignore exceptions' Query Failed: SQLSTATE [HY093]: Invalid parameter number of bound number variable does not match the number of tokens'  

but if I PDO :: ATTR_EMULATE_PREPARES code> false Bdlunga, then threw an exception I will not just go to false in the $ result for security reasons I want to emphasize exceptions in this case, but I I am not seeing how to reach it. Any suggestions would be most welcome.

Edit 1

using PDO :: ATTR_EMULATE_PREPARES = & gt; False , if i would var_dump ($ Ps-> errorInfo ()) I get:

  array (3) {[0] = & Gt; String (5) "HY093" [1] = & gt; Int (7) [2] = & gt; String (0) ""}  

First of all, if we try PostgreSQL Exits errors by executing a prepared statement with more and more parameters.

Demo in psq:

  test => Prepare as P + 1 + $ 1; Prepare Exam & gt; Execute P (1); ? Column? ---------- 2 (1 line) test = & gt; Execute P (1,2); Error: The expected number of parameters for the prepared statement "P": 1 parameter expected, but got 2.  

When PHP / PDOs are used with the correct statement, then the PDO layer must be posted before the query from the postgren (the preparation is deferred, its another is deferred Some other details in the question have been mentioned with :).

PHP 5.3.10-1ubuntu3.15, PG 9.1 (Ubuntu 12.04)

   1, ": other" => 2)); Var_dump ($ stmt-> fetchAll ()); } Hold (PDOException $ e) {echo "error" $ e-> incoming message (). "\ N"; }? & Gt;  

This generates:

Error SQLSTATE [HY093]: Invalid parameter number :: Other

A As a comparison point,

  $ pdo-> Set attribute (PDO: ATTR_EMULATE_PREPARES, true) with the same exam; (Emulated ready statement) generates an error, with a different error message, any of the questions outlined in the question: 

Error SQLSTATE [HY093] : Invalid parameter number: Number of bound variables does not match the number of tokens

Ensure that you are using the latest version of PHP / PDO.


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -