Mysqli_query () warning parameter 1 for mysqli, null set. Database Error

I get this warning:

( ! ) Warning: mysqli_query() expects parameter 1 to be mysqli, null given in C:\wamp\www\inc\functions.php on line 73 Call Stack # Time Memory Function Location 1 0.0003 251048 {main}( ) ..\manage_user.php:0 2 0.0012 295000 find_all_users( ) ..\manage_user.php:8 3 0.0012 295376 mysqli_query ( ) ..\functions.php:73 Database query failed. 

I read several posts on it and realized that the error was in the first line in my mysqli_query ($ db, $ query).

It will be $ db, this is what I find strange. mysqli_query ($ db, $ query) works fine for all other functions. but when I call the find_all_users () function, I get a warning.

dbcon:

  define("DB_SERVER", "localhost"); define("DB_USER", "*******"); define("DB_PASS", "*******"); define("DB_NAME", "*******"); // 1. Create a database connection $db = mysqli_connect(DB_SERVER, DB_USER, DB_PASS, DB_NAME); // Test if connection succeeded if(mysqli_connect_errno()) { die("Database connection failed: " . mysqli_connect_error() . " (" . mysqli_connect_errno() . ")" ); } 

features:

 function find_all_users() { global $db; $query = "SELECT * "; $query .= "FROM user "; $query .= "ORDER BY username ASC"; $user_set = mysqli_query($db, $query); confirm_query($user_set); return $user_set; } function confirm_query($result_set) { if (!$result_set) { die("Database query failed."); } } 

page to which I am receiving a warning:

 <?php require_once($_SERVER['DOCUMENT_ROOT'].'/session/session.php'); require_once($_SERVER['DOCUMENT_ROOT'].'/inc/functions.php'); include($_SERVER['DOCUMENT_ROOT'].'/inc/header.php'); include($_SERVER['DOCUMENT_ROOT'].'/inc/nav_ribbon.php'); $user_set = find_all_users(); ?> <body> <div id="p2dbg"> <div id="p2dcontent"> <?php include($_SERVER['DOCUMENT_ROOT'].'/inc/left_container.php'); ?> <div id="page"> <?php echo message(); ?> </div> </div> <?php include($_SERVER['DOCUMENT_ROOT'].'/inc/footer.php'); ?> </div> </body> </html> 
+4
source share
1 answer

$db was null because the dbcon file dbcon not included:

 include('dbcon.php'); session_start(); 
+2
source

Source: https://habr.com/ru/post/1495813/


All Articles