douyun7718 2016-03-23 15:04
浏览 52

使用PHP的SQL Server查询 - 法语中的特殊字符

I'm searching for a field in a SQL server 2005 table. I'm using something like

$query = "select * from TableName where replace ( replace ( client , 'é' ,'e' ) , 'ç' ,'c' ) COLLATE French_CI_AI = 'Agence française du texte agréable'"; 

I can ask the table to get the name without the 'where' clause, but I can not ask it if I use this specific name 'Agence française du texte agréable' in a where clause

Every other names are working so I suppose that the problem is related to the 'ç' or 'é' character

thank you for your help !

------------- EDIT --------------

thank you for your anwser. I have made another test by removing the ç and é, like this 'Agence francaise du texte agreable'

And I still can't get the infos ! So finally where is my problem ? ... I also tested $query = "select * from Table where client = 'Agence francaise du texte agreable'";

and the var_dump returns resource(4, SQL Server Statement)

and the var_dump of the fetch_array, returns null

I don't understand ... it works with other names :(

---------- EDIT 2 --------------

Found that my problem comes from the fact that I had only one result, and my code did not work then. Then changed my code with

$query = "select * from Table where client COLLATE French_CI_AI = 'Agence française du texte agréable'"; 

// SQLSrv_num_rows requires a static or keyset cursor.
if (strncmp(ltrim(strtoupper($query)), 'SELECT', strlen('SELECT')) == 0)
{
$array = array('Scrollable' => SQLSRV_CURSOR_KEYSET);
}
else
{
$array = array();
}

$cursor = sqlsrv_query($db, $query, array(), $array);
$row = sqlsrv_fetch_array($cursor, SQLSRV_FETCH_NUMERIC);

thank you all for your help!

  • 写回答

1条回答 默认 最新

  • dongshushi5579 2016-03-23 15:17
    关注

    I don't think you even need to remove the special characters at all (ie: the replace() ) why not just just do:

    $query = "select * from TableName COLLATE French_CI_AI = 'Agence française du texte agréable'"; 
    

    then if you really want to remove the french characters for whatever reason:

    $result = str_replace("é", "e", str_replace("ç", "c"$result);

    This way you can still replace the French characters and not mess up your query.

    评论

报告相同问题?

悬赏问题

  • ¥15 目详情-五一模拟赛详情页
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?
  • ¥15 加热介质是液体,换热器壳侧导热系数和总的导热系数怎么算
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line