I made a set up for showing tables with a php script.
Its based on a script from w3schools.
// make connection with localhost $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // script calling to connect with dbase function write_content () { // reading the tables from the dbase $sql = "SHOW TABLES"; // show tables $result = $conn->query($sql); while ($row = $result->fetch_assoc()) { echo current($row) . '<br/>'; } $conn->close(); return; } echo "<br><br><br>"; echo "The following tables are found in the database " ; echo write_content ();
The problem is that conn is a not defined variable.though it worked in a condition with if.
Then a second error message is given sounding:
Fatal error: Call to a member function query() on a non-object in .....
these errors concern this line:
$result = $conn->query($sql);