|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-10-01 06:03 UTC] matthias dot djihangiroff at persona dot de
Description:
------------
The bindParam() throws an SQLSTATE[22001]: String data, right truncated exception at CLI only.
In an Apache context, all went fine.
Reproduce code:
---------------
$INFORMIXDIR = getenv("INFORMIXDIR");
$connectionString2 = "informix:host=ux10001; service=1528; database=db10001; server=tcp10001; protocol=onsoctcp; EnableScrollableCursors=1;TRANSLATIONDLL=$INFORMIXDIR/lib/esql/igo4a304.so";
$pdo2 = new PDO($connectionString2, "", "");
$pdo2->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$suchstring = "Matthias";
$stmt2 = $pdo2->prepare("SELECT nbwvorname from snbewer where nbwvorname like :name");
$stmt2->bindParam(':name', $suchstring, PDO::PARAM_STR);
$stmt2->execute();
print_r($stmt2->fetchAll());
Expected result:
----------------
Array
(
[0] => Array
(
[NBWVORNAME] => Matthias
[0] => Matthias
)
}
Actual result:
--------------
PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[22001]: String data, right truncated: -11023 [Informix][Informix ODBC Driver]String data right truncation. (SQLExecute[-11023] at /tmp/pear/download/PDO_INFORMIX-1.2.6/informix_statement.c:755)' in /srv/www/htdocs/django/test27.php:21
Stack trace:
#0 /srv/www/htdocs/django/test27.php(21): PDOStatement->execute()
#1 {main}
thrown in /srv/www/htdocs/django/test27.php on line 21
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 18:00:01 2025 UTC |
Some additional information: Assuming we created a table X with a column Y defined as char(5): $stmt = $db->prepare("SELECT * FROM X WHERE Y like ?"); $stmt->bindParam(1, $Z); $stmt->execute(); This works, as long, as len($Z) <= 5 - if its longer, than it breaks. Another testcase: $stmt = $db->prepare("SELECT * FROM X WHERE Y || Y like ?"); $stmt->bindParam(1, $Z); $stmt->execute(); This breaks the moment len($Z) > 0 (any usable case). So basicly I would have to fall back to: $stmt->query( sprintf("SELECT * FROM X WHERE Y || Y like %s", $db->quote($Z) ); This could be also either done in the driver or corretly solved (prefered).Ok - now I reproduced the problem with the Informix Demo-Appliance - I changed the most basic example to use the feature(?) bindValue: ids1150srvr:/opt/IBM # diff -u ./informix/FirstSteps/03_PHP/HelloWorld.php ./OpenAdmin/Apache_2.2.4/htdocs/HelloWorld.php --- ./informix/FirstSteps/03_PHP/HelloWorld.php 2009-04-29 21:26:02.000000000 -0400 +++ ./OpenAdmin/Apache_2.2.4/htdocs/HelloWorld.php 2009-10-14 19:59:57.000000000 -0400 @@ -4,10 +4,13 @@ try { $db = new PDO("informix:host=ids1150srvr; service=9088; database=stores; server=demo_on; protocol=onsoctcp; EnableScrollableCursors=1;", "informix", "informix"); +$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); print "Hello World!</br></br>"; print "Connection Established!</br></br>"; -$stmt = $db->query("select * from customer"); +$stmt = $db->prepare("select * from customer WHERE fname || fname like ?"); +$stmt->bindValue(1, '%Carole%'); +$stmt->execute(); $res = $stmt->fetch( PDO::FETCH_BOTH ); $rows = $res[0]; echo "Table contents: $rows.</br>"; ids1150srvr:/opt/IBM # This produces an exception. The same happens then fname colum concatenation is not done, but a string with a length 16 or greater is used.in the bind.Description: ------------ I have a very similar problem when calling stored procedures. Server is IDS 11.50uc4 running on Debian. The problem is reproducable on both Windows and Linux clients running PHP 5.2.x (both CLI and Apache), PDO_INFORMIX 1.2.6 and Informix Client SDK 3.50. The problem is when calling the following stored procedure: CREATE PROCEDURE test_proc( param varchar(10) ) END PROCEDURE; Reproduce code: --------------- <?php $db_url = "informix:host=tstdb; service=1526; database=buba; server=tstdb; CLIENT_LOCALE=hr_hr.1250; DB_LOCALE=hr_hr.1250"; $db = new PDO($db_url, '<user>', '<pass>'); $query = "EXECUTE PROCEDURE test_proc(:param)"; $args = array('param' => 'abc'); $db = new PDO($db_url, $username, $password); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $db->prepare($query); $stmt->execute($args); ?> Expected result: ---------------- Statement is executed. Actual result: -------------- PDO Exception thrown with the following message: SQLSTATE[22001]: String data, right truncated: -11023 [Informix][Informix ODBC Driver]String data right truncation. (SQLExecute[-11023] at /root/PDO_INFORMIX-1.2.6/informix_statement.c:757) Notes ----- * The same happend when using bindValue or bindParam methods to pass the value of ':param'. * The same happend when using unnamed parameters ('?' instead of ':param'). * The exception is always thrown from execute(), not bindValue or bindParam as described by matthias. * The error does NOT appear if the ':param' argument value is an empty string. All other values trigger the above error.