I am trying to get my PHP code to connect to my database hosted on the same server, but no matter what I do, it always ends up returning an empty set.
$servername = "localhost";
$username = "user";
$password = "pass";
$dbnom = "name";
$conn = new mysqli($servername, $username, $password, $dbnom);
mysqli_set_charset($conn, "utf8");
if(!$conn) {
die("La connexion a échoué : " . mysqli_connect_error());
}
$championsSQL = "SELECT pa_championId FROM participants";
$resultSQL = mysqli_query($conn, $championsSQL);
if(mysqli_num_rows($resultSQL) > 0) {
while($row = mysqli_fetch_assoc($resultSQL)) {
echo "Nom des champions : " . $row["pa_championId"] . "<br>";
}
}
else {
echo "Aucun résultat";
}
var_dump($resultSQL);
mysqli_close($conn);
The MySQL request "SELECT pa_championId FROM participants" works when I enter it manually into the mysql command line on the server. The var_dump at the end always returns NULL. The PHP is from the "Select Data With MySQLi section of this website : https://www.w3schools.com/php/php_mysql_select.asp
I know this question has been posted many times before, but none of the answers I found fit my exact situation.