unixODBC + PHP , Invalid string or buffer length error message
-
09-10-2019 - |
Question
I access to an AS400/DB2 with PHP via unixODBC
But some field name of my AS400 are named with "££.." (it can't be changed)
And when I tried to launch an sql query from my PHP page
select * from LIBNAME.TABLE where ££FIELD like 'test%'
I always get the same error message
SQL error: [unixODBC][IBM][System i Access ODBC Driver]Invalid string or buffer length., SQL state S1090 in SQLExecDirect
If someone have clue.
Solution
Try adding this statement before the query execution:
setlocale(LC_CTYPE, 'en_US');
For a more detailed description of the issue: http://bugs.centos.org/view.php?id=3187
OTHER TIPS
DB2 should have some way of enclosing the identifiers. Some databases use double quotes
select * from "tableID" where "fieldID" like 'blah%'
mySQL uses backticks. Not sure with DB2 but shouldn't be too hard to find out and try. If that doesn't work, see if there is a way to represent characters by hex value in a string. Like 'hello\x0A\x0Dthere' would be the words 'hello' and 'there' separated by a line-break. You may just need to find the value for £.