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
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>
source share