I have a MySQL database on my hosting and am trying to query it with PHP on a dedicated PHP file, content.php :
<?php
//on inclue un fichier contenant nom_de_serveur, nom_bdd, login et password d'accès à la bdd mysql
include ("membersarea/connect.php");
//on se connecte à la bdd
$connexion = mysqli_connect (SERVEUR, LOGIN, MDP);
if (!$connexion) {echo "LA CONNEXION AU SERVEUR MYSQL A ECHOUE\n"; exit;}
mysqli_select_db ($connexion, BDD); print "Connexion BDD reussie";echo "<br/>";
$result = mysqli_query($connexion, "SELECT contenu FROM content WHERE id=1");
$text = mysqli_fetch_field($result);
?>
I want to display the BDD data on my index.php file so I included the content.php at the begining of index.php :
<?php
include ("content.php");
?>
and display between HTML balises with :
<?= $text ?>
Unfortunately i get the following error "Recoverable fatal error: Object of class stdClass could not be converted to string"
I don't really understand why (as the data in the DB is a "text") or how to fix it. Thank you for reading until here, any help is welcome ! :)
<?= $text->contenu ?>, then read fetch_field theres an example to fetch all rows