Working with characters with accents in sql query and table name

不羁岁月 提交于 2019-12-23 03:11:25

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!