php – 特殊字符无法插入数据库

我是PHP新手.我试图读取文本文件并逐行插入数据库.我的问题是一些特殊的字符插入查询不起作用
例如Côte,d.ä.,d.y.,DAB-sändare这些都在起作用.但不能插入代办.如果我删除了d affaires然后查询将执行否则它将不会向数据库插入任何数据.我用来reaf并插入数据库PHP代码

MysqL_connect("localhost","root","");
    MysqL_select_db("testdb");
    $query="INSERT INTO keywords (id,keyword) VALUES ";
    $handle = fopen("Ordlista.txt","r");
    if ($handle) {
        $i=1;
        while (($line = fgets($handle)) !== false) {
            // process the line read.
           // echo $line.'MysqL_query($query);
    } else {
        echo 'error opening the file.';
        // error opening the file.
    } 
    fclose($handle);

更新
我在wordpress中创建插件时使用了此代码,然后特殊字符插入为“?”.在前面的代码中,我正在完成的代码更改是工作文件

MysqL_query("TruncATE TABLE $table");
//    $structure = "INSERT INTO $table (`id`,`keyword`) VALUES (NULL,'test1'),(NULL,'test2');"; // Keywords for Testing
//    $wpdb->query($structure);
   //read text file & insert to database start
   $query="INSERT INTO $table (id,keyword) VALUES ";
   $fllocation=PLG_URL.'/Ordlista.txt';
    $handle = fopen($fllocation,"r");
    if ($handle) {
        $i=1;
        while (($line = fgets($handle)) !== false) {
            // process the line read.
            if($i==1)
            {
            $query.=" ( NULL,'".MysqL_real_escape_string($line)."') ";
            $i++;
            }
            else {
                $query.=",'".MysqL_real_escape_string($line)."') ";
            }
        }
        $query.=";";
        $wpdb->query($query);
       // echo $query;
       // MysqL_query($query);
    } else {
        echo 'error opening the file.';
        // error opening the file.
    } 
    fclose($handle);
最佳答案
试试MysqL_real_escape_string();

MysqL_connect("localhost",'".MysqL_real_escape_string($line)."') ";
            }

        }
        $query.=";";
     //   $qr=htmlspecialchars($query,ENT_QUOTES);
        echo $query;
        MysqL_query($query);
    } else {
        echo 'error opening the file.';
        // error opening the file.
    } 
    fclose($handle);

相关文章

优化MySQL数据库发布系统存储的方法有:1.mysql库主从读写分...
使用mysql的方法:在“我的电脑”→右键→“管理”→“服务”...
在mysql中查看root用户权限的方法:1.命令行启动mysql服务;...
MySQL主从复制是用来备份一个与主数据库一样环境的从数据库,...
运行mysql的方法1.启动mysql服务,在“我的电脑”→右键→“...
开启mysql的方法1.可以通过快捷键win+r,输入cmd,打开窗口,...