PHP, ODBC, and nvarchar
I stumbled upon an odd error using PHP's ODBC functions to query a SQL Server 2005 database. I was doing a basic SELECT statement to get the description of something when I encountered the following error:
Warning: odbc_exec() [function.odbc-exec]: SQL error: [unixODBC][FreeTDS][SQL Server]Unicode data in a Unicode-only collation or ntext data cannot be sent to clients using DB-Library (such as ISQL) or ODBC version 3.7 or earlier., SQL state in SQLExecDirect in /home/web/file.php on line 4
It turns out that the PHP ODBC functions have a hard time pulling "nvarchar" data. Here's the ugly solution to getting nvarchar data:
SELECT CAST(CAST([DetailedDescription] AS VARCHAR(8000)) AS TEXT) AS ad FROM mytable WHERE active = 1
Not pretty but making it function is what counts.
While synchronous code is easier to follow and debug, async is generally better for performance and flexibility. Why "hold up the show" when you can trigger numerous requests at once and then handle them when each is ready? Promises are becoming a big part of the JavaScript world...
I work with an awesome cast of developers at Mozilla, and one of them in Daniel Buchner. Daniel's shared with me an awesome strategy for detecting when nodes have been injected into a parent node without using the deprecated DOM Events API.
One event that's always been lacking within the document is a signal for when the user is looking at a given tab, or another tab. When does the user switch off our site to look at something else? When do they come back?
We all know that do/undo functionality is a God send for word processing apps. I've used those terms so often that I think of JavaScript actions in terms of "do" an "undo." I've put together a proof of concept Do/Undo class with MooTools.
The MooTools...
THANKS!!!
muchas gracias.. ahora puedo seguir trabajando tranquilo.. justamante estaba teniendo problemas con un campo nvarchar.
Casting to varchar limits you to 8000 characters in a field.
I found just casting to text works better, like so:
Thanks , nice solve problem from sql server
Cast did the job ….
Nice post !!!
not work!
Warning: mssql_query() [function.mssql-query]: message: Incorrect syntax near ‘ASâ’. (severity 15) in /var/www/vhosts/fvc.ir/httpdocs/mssql.php on line 11
Thank you very very much!
And here is how to write value:
http://stackoverflow.com/questions/7255703/utf-8-in-sql-server-2008-database-php
thanks a lot. i was not shure what was the problem. In the sql management studio the data looks fine and in php is not. my first impresion was user rights for the data .. but after 1 hour of hair pulling :) i wandered if culd be the odbc … and like this i found your post
thanks again
Thanks for this solution. I was stuck at this problem and finally reached here