doujiang1913 2013-10-09 09:35
浏览 60
已采纳

在mysql中不在键盘上插入双引号和单引号

I have trying to insert the double quotes other than keyboard

for ex :

statement : Ashley is studying for an exam. During her review, she notes that “semantic” denotes “meaning” and thinks about how this relates to semantic memory. A second review showed her that

It get converted to following after being inserted into mysql database:

Ashley is studying for an exam. During her review, she notes that “semantic†denotes “meaning†and thinks about how this relates to semantic memory. A

I have converted all the tables and database into utf-8 collation and also used meta tag for utf-8 but with no success. Can someone identify the issue.

  • 写回答

1条回答 默认 最新

  • duanlieshuang5330 2013-10-09 09:39
    关注

    I always do it like this:

    $db = new mysqli('localhost','root','','db');
    $cod = $db->query("SET NAMES 'utf8'"); //Set the encoding
    

    This code was working for me (just now):

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>ab</title>
    <script type="text/javascript">
    
    
    </script>
    </head>
    
    <body>
    <?
    $db = new mysqli('localhost','root','','test');
    $cod = $db->query("SET NAMES 'utf8'");
    $result = $db->query("INSERT INTO `test`(`string`) VALUES ('".addslashes("“teststring“")."')");
    $result = $db->query("SELECT `string` FROM `test` WHERE string='".addslashes("“teststring“")."'");
    
    $result= $result->fetch_assoc();
    echo $result['string'];
    
    ?>
    </body>
    </html>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法