Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/72.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读取txt文件(file_get_contents)以从mysql获取数据到html表时没有结果_Php_Mysql_Html - Fatal编程技术网

使用php读取txt文件(file_get_contents)以从mysql获取数据到html表时没有结果

使用php读取txt文件(file_get_contents)以从mysql获取数据到html表时没有结果,php,mysql,html,Php,Mysql,Html,我试图通过读取php中的txt文件,从mysql中的表中查询一些数据 请注意,我尝试了mysqli,但没有得到任何结果! 下面是我的代码: $dbhost = "localhost"; $dbutilisateur = "root"; $dbpasse = ""; $dbnom = "test"; $file= file_get_contents("List.txt"); $data = $file; $connexion = new PDO('mysql:host=' . $dbhos

我试图通过读取php中的txt文件,从mysql中的表中查询一些数据

请注意,我尝试了mysqli,但没有得到任何结果! 下面是我的代码:

$dbhost = "localhost";
$dbutilisateur = "root";
$dbpasse = "";
$dbnom = "test";

$file= file_get_contents("List.txt");
$data = $file;


$connexion = new  PDO('mysql:host=' . $dbhost . ';dbname=' . $dbnom, 
$dbutilisateur, $dbpasse);

if(isset($_GET['action'])){


$sql = 'SELECT * FROM servers
            WHERE cpu_manufacturer = $data';


$req_prepare= $connexion->prepare($sql);

$req_prepare->execute();

$result = $req_prepare->fetchAll(PDO::FETCH_ASSOC);




$contenu = '';

$contenu .= '

   <table class="table table-bordered">

    <tr>

     <th width="26,66%">cpu_manufacturer</th>

     <th width="26,66%">server_location</th>

     <th width="26,66%">provider_name</th>

    </tr>

';

if($req_prepare->rowCount() > 0)
    {
        foreach($result as $row)

    {
        $contenu .= '

        <tr>

 <td style="background:whitesmoke">'.$row["cpu_manufacturer"].'</td>

 <td style="background:whitesmoke"">'.$row["server_location"].'</td>

 <td style="background:whitesmoke"" >'.$row["provider_name"].'</td>


        </tr>
    ';
    }
 }

 else

    {

    $contenu .= '

     <tr>

     <td align="center">No data found!</td>

     </tr>

   ';

   }

  $contenu .= '</table>';

  echo $contenu;


}
$dbhost=“localhost”;
$dbusilisateur=“root”;
$dbpasse=“”;
$dbnom=“测试”;
$file=文件获取内容(“List.txt”);
$data=$file;
$connexion=new PDO('mysql:host='.$dbhost'.;dbname='.$dbnom,
$dbusilisateur,$dbpasse);
如果(isset($_GET['action'])){
$sql='SELECT*来自服务器
其中cpu_制造商=$data';
$req_prepare=$connexion->prepare($sql);
$req_prepare->execute();
$result=$req_prepare->fetchAll(PDO::FETCH_ASSOC);
$contenu='';
$contenu.='
中央处理器制造商
服务器位置
提供者名称
';
如果($req\u prepare->rowCount()>0)
{
foreach($结果为$行)
{
$contenu.='
“.$row[“cpu_制造商”]”
“.$row[“提供者名称”]”
';
}
}
其他的
{
$contenu.='
没有找到任何数据!
';
}
$contenu.='';
echo$contenu;
}
以下是文本文件的内容:

cpu_制造商:AMD 服务器位置:美国 供应商名称:AAAA


非常感谢您的回复

您是从文本文件还是从数据库获取数据

如前所述,查询的计算结果为

SELECT * FROM servers
        WHERE cpu_manufacturer = (SELECT cpu_manufacturer FROM servers
        WHERE cpu_manufacturer= cpu_manufacturer: AMD server_location: USA provider_name: AAAA)

即使您将文本文件中的数据用单引号括起来,作为查询中需要的文本值,您仍然无法从数据库中获取任何信息-您的查询构造得非常糟糕。

好吧,我首先从txt文件中读取数据,并将其放在查询中,以便从我的表中获取数据。假设cpu_制造商是“AMD”,那么它将检查我的表以获取行等等……你是对的,但这个问题没有很好的答案。我的是先从一个txt文件中读取数据。这就是为什么我在这里再次发布我的!我的查询本身在phpmyadmin中运行良好。但是我不知道为什么在我的php代码中会出现这个PDO语句错误……在phpMyAdmin中“工作正常”的确切查询是什么?