0

I am separating calling script and the query script index.php:

require_once('./connection.php');

findAll('user');

and my connection.php contains

$conn = new mysqli('localhost', "root", "", "test");
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

function findAll($tableName){
    $sql = "SELECT * FROM $tableName";
    $result = $conn->query($sql);
    while($row = $result->fetch_assoc()) {
       echo "<pre>";print_R($row);echo "</pre>";
    }
}

but it return an error message

Fatal error: Call to a member function query() on null in F:\wamp\www\scaff\connection.php on line 9

code on line no 9:

$result = $conn->query($sql);

can you please help me to find reason why it is not getting access to global function

Paritosh Mahale
  • 1,238
  • 2
  • 14
  • 42

0 Answers0