I am trying to query some data from my table in mysql by reading a txt file in php.
Please Note that I tried with mysqli and got no result ! below is my code:
$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;
}
Below is the content of text file:
cpu_manufacturer: AMD server_location: USA provider_name: AAAA
Your response will be greatly appreciated!