Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 无法在mysql中搜索Unicode数据_Php_Mysql_Unicode - Fatal编程技术网

Php 无法在mysql中搜索Unicode数据

Php 无法在mysql中搜索Unicode数据,php,mysql,unicode,Php,Mysql,Unicode,我有一个表orders,其中数据以Unicode格式存储。其他数据采用unicode格式,即印地语 随函附上表格结构的屏幕截图。 从这张图片可以查看表中存储的数据。 表的sql转储如下所示: CREATE TABLE IF NOT EXISTS `orders` ( `sno` varchar(11) NOT NULL, `CaseNO` varchar(255) NOT NULL, `Court` varchar(255) NOT NULL, `Yr` va

我有一个表orders,其中数据以Unicode格式存储。其他数据采用unicode格式,即印地语

随函附上表格结构的屏幕截图。 从这张图片可以查看表中存储的数据。

表的sql转储如下所示:

CREATE TABLE IF NOT EXISTS `orders` (
    `sno` varchar(11) NOT NULL,
    `CaseNO` varchar(255) NOT NULL,
    `Court` varchar(255) NOT NULL, 
    `Yr` varchar(4) NOT NULL,
    `CaseType` varchar(50) NOT NULL,
    `Dt_Disposal` varchar(10) NOT NULL, 
    `App_Name` longtext NOT NULL, 
    `App_F_Name` longtext NOT NULL, 
    `Res_Name` text NOT NULL, 
    `Res_F_Name` text NOT NULL, 
    `Pet_Cou_Name` varchar(255) NOT NULL, 
    `Res_Cou_Name` varchar(255) NOT NULL, 
    `Pro_Off_Name` varchar(255) NOT NULL,
    `District` varchar(255) NOT NULL, 
    `Division` varchar(255) NOT NULL,
    `Tehsil` varchar(255) NOT NULL, 
    `Path` longtext NOT NULL, 
    `UName` varchar(255) NOT NULL, 
    `CCY` varchar(255) NOT NULL, 
    `Page_Cnt` int(11) NOT NULL,
    `Dis_year` varchar(4) NOT NULL, 
    PRIMARY KEY (`sno`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
-

-表订单的转储数据\u bkp 搜索参数的代码如下所示

 $mysqli_link= new mysqli("localhost", "root", "", "revenue");
 mysqli_set_charset( $mysqli_link, 'utf8');
 if($_POST['id_sflag']=='1') 
 {
 // define the list of fields
 $fields = array('CaseNO', 'Yr', 'CaseType', 'Court', 'Dt_Disposal', 'App_Name', 'Res_Name', 'Pet_Cou_Name', 'Res_Cou_Name', 'District', 'Pro_Off_Name', 'Division', 'Tehsil');
$conditions = array();
 }

 // builds the query
 $query = "SELECT * from orders";

 // loop through the defined fields
 foreach($fields as $field){
// if the field is set and not empty
if(isset($_POST[$field]) && !empty($_POST[$field])) {
    // create a new condition while escaping the value inputed by the user (SQL Injection)
    $conditions[] = "$field LIKE '%" . mysqli_real_escape_string($mysqli_link, $_POST[$field]) . "%'";
    }
}
 // if there are conditions defined
 if(count($conditions) > 0) {
// append the conditions
$query .= " WHERE " . implode (' AND ', $conditions); // you can change to 'OR', but I suggest to apply the filters cumulative
 }

 echo "$query<br>";

 $result = mysqli_query($mysqli_link, $query);
 //var_dump($result);
 $num_rows=mysqli_num_rows($result);
 mysqli_close($mysqli_link);
当在phpmyadmin中运行时,这个查询工作得非常好,我在phpmyadmin中得到了结果。但当运行Php页面时,它确实返回0条记录

我的代码正在构建一个从上一页传递过来的动态查询,它可以有13个搜索参数

 $mysqli_link= new mysqli("localhost", "root", "", "revenue");
 mysqli_set_charset( $mysqli_link, 'utf8');
 if($_POST['id_sflag']=='1') 
 {
 // define the list of fields
 $fields = array('CaseNO', 'Yr', 'CaseType', 'Court', 'Dt_Disposal', 'App_Name', 'Res_Name', 'Pet_Cou_Name', 'Res_Cou_Name', 'District', 'Pro_Off_Name', 'Division', 'Tehsil');
$conditions = array();
 }

 // builds the query
 $query = "SELECT * from orders";

 // loop through the defined fields
 foreach($fields as $field){
// if the field is set and not empty
if(isset($_POST[$field]) && !empty($_POST[$field])) {
    // create a new condition while escaping the value inputed by the user (SQL Injection)
    $conditions[] = "$field LIKE '%" . mysqli_real_escape_string($mysqli_link, $_POST[$field]) . "%'";
    }
}
 // if there are conditions defined
 if(count($conditions) > 0) {
// append the conditions
$query .= " WHERE " . implode (' AND ', $conditions); // you can change to 'OR', but I suggest to apply the filters cumulative
 }

 echo "$query<br>";

 $result = mysqli_query($mysqli_link, $query);
 //var_dump($result);
 $num_rows=mysqli_num_rows($result);
 mysqli_close($mysqli_link);
检索代码为:

 while($row = mysqli_fetch_array($result)) 
                 {
                    $dis=$row['District'];
                    $div=$row['Division'];
                    $teh=$row['Tehsil'];
                    $cnt1=$row['Page_Cnt'];
                    $dyear=$row['Dis_year'];
                    $filen=$row['CCY'];
                    $newfile=$string = str_replace("/","_",$filen);
                    $newfile1="judgements/"."$dyear"."/"."$newfile".".pdf";
                    $Appname=$row['App_Name'];
                    $resname=$row['Res_Name'];
                    $disposal=$row['Dt_Disposal'];
                    $officer=$row['Pro_Off_Name'];
                    $pcnt=$row['Page_Cnt'];
                    printf("
                  <tr> 
                    <td class=\"sub6\">%s</td>
                    <td class=\"sub6\">%s</td>
                    <td class=\"sub6\">%s</td>
                    <td class=\"sub6\">%s</td>
                    <td class=\"sub6\">%s</td>
                    <td class=\"sub6\">%s</td>
                    <td class=\"sub6\">%s / %s  / %s</td>
                    <td class=\"sub6\">%s</td>
                    <td class=\"sub6\"><a href=\"%s\">View Order</a></td>
                      </tr>\n",$i,$filen,$Appname,$resname,$disposal,$officer,$dis,$div,$teh,$pcnt,$newfile1);
                $tot=$tot+$cnt1;  
              $i=$i+1;
              }
查询没有问题,但不知何故它不会获取存储在数据库中的unicode数据的记录


欢迎提出任何建议

我已经找到了答案。然而,这个网站并没有给出答案

我在表单页面和结果页面上遗漏了以下语句

header('Content-type: text/html; charset=UTF-8');

我加了这句话,效果很好

我在这里粘贴的查询就是已经构建的查询。观察echo$query标记。我已经回显了查询以检查它,并将其粘贴到这里。您必须创建一个最小的完整可验证示例。这是一个代码,创建一个表,插入一个值,然后尝试重新选择它-这样任何人都可以运行它并确认您的问题,我可以将示例代码发送给您。它将有完整的代码、表结构和数据以及页面。这应该是一个最小的例子。通过单击此链接可以下载代码示例,您可以重新创建场景。无论何时搜索英语参数,都会执行查询。无论何时搜索unicode字段,它都不起作用。当前浏览器通常默认为该字段。是的,它们会这样做。事实上,我的代码已经有了这个功能,但它仍然不起作用。添加了上面的行,它就工作了
 while($row = mysqli_fetch_array($result)) 
                 {
                    $dis=$row['District'];
                    $div=$row['Division'];
                    $teh=$row['Tehsil'];
                    $cnt1=$row['Page_Cnt'];
                    $dyear=$row['Dis_year'];
                    $filen=$row['CCY'];
                    $newfile=$string = str_replace("/","_",$filen);
                    $newfile1="judgements/"."$dyear"."/"."$newfile".".pdf";
                    $Appname=$row['App_Name'];
                    $resname=$row['Res_Name'];
                    $disposal=$row['Dt_Disposal'];
                    $officer=$row['Pro_Off_Name'];
                    $pcnt=$row['Page_Cnt'];
                    printf("
                  <tr> 
                    <td class=\"sub6\">%s</td>
                    <td class=\"sub6\">%s</td>
                    <td class=\"sub6\">%s</td>
                    <td class=\"sub6\">%s</td>
                    <td class=\"sub6\">%s</td>
                    <td class=\"sub6\">%s</td>
                    <td class=\"sub6\">%s / %s  / %s</td>
                    <td class=\"sub6\">%s</td>
                    <td class=\"sub6\"><a href=\"%s\">View Order</a></td>
                      </tr>\n",$i,$filen,$Appname,$resname,$disposal,$officer,$dis,$div,$teh,$pcnt,$newfile1);
                $tot=$tot+$cnt1;  
              $i=$i+1;
              }
header('Content-type: text/html; charset=UTF-8');