i'm new to php PDO, i've made a query to select users in db and display them in a html table but i get no result, and there is no error message. print_r($connexion)
returns PDO Object ( )
here is the code. thanks for your help!
connexion to db //connexion.php
function connexion(){
try {
$dns = 'mysql:host = localhost; dbname = pruf';
$utilisateur = 'root';
$motDePasse = '';
$connexion = new PDO($dns, $utilisateur, $motDePasse, array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'
));
}
catch (Exception $ex) {
echo "connexion à Mysql impossible", $ex->getMessage();
die('ok');
}
return $connexion;
query file //searchInvite.php
<!DOCTYPE HTML>
<head>
<meta charset="utf-8"
</head>
<html>
<table border="1px">
<tr>
<td>Nom</td>
<td>Prenom</td>
<td>Fonction</td>
<td>Titre</td>
<td>Adresse</td>
</tr>
<?php
require_once 'connexion.php';
$connexion = connexion();
print_r($connexion);
$query = "SELECT nom, prenom, fonction, titre_grade, adr_pro_voie FROM invite ORDER BY id LIMIT 0 , 30";
$stmt = $connexion->prepare($query);
$stmt->execute();
while ($enregistrement = $stmt->fetchAll(PDO::FETCH_OBJ)){
?>
<tr>
<td><?php echo $enregistrement->nom; ?></td>
<td><?php echo $enregistrement->prenom; ?></td>
<td><?php echo $enregistrement->fonction; ?></td>
<td><?php echo $enregistrement->titre_grade ?></td>
<td><?php echo $enregistrement->adr_pro_voie; ?></td>
</tr>
<?php
}
?>
</table>