问题
I'm doing some php & SQL Server 2005 in a database with accents ( é , è , à ) in both tables names , columns names and fields . Unfortunately , I'm not the owner/creator of this database , but I agree that the owner must be slapped :) .
Im using ODBC driver to connect to the SQL Server odbc_connect($dsn,$user,$password)
.
My problem is that every fields with accents is not recognized . For example : despite having 7000 fields with the name "Réseau"
$query="Select * from dbo.Table where col1= 'Réseau'"
gives 0 results No rows found
Same thing for :
$query="Select * from [dbo].[Tablé]
giving an sql error :
Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]Object name 'dbo.Tablé' not valid., SQL state S0002 in SQLExecDirect in...
And , sadly , none of the tips i found over the net helped , like :
'Réseau' , Réseau
, [Réseau] , COLLATE SQL_Latin1_General_Cp437_CI_AI/French_CI_AS ...
For more info , I'm using charset UTF-8 , my database collate is French_CI_AS . And all the querys above works perfectly on Access or Query Tools (Using ODBC) .
- * EDITED to clarify more *
回答1:
try
$q="Select * from DatabaseTable where col1= N'Réseau'"
回答2:
Try setting your locale in your page, I found setting mine helped with all the special characters :
setlocale (LC_ALL, 'nl_BE');
来源:https://stackoverflow.com/questions/10910354/working-with-characters-with-accents-in-sql-query-and-table-name