相关文章推荐
大力的松鼠  ·  Mysql比较日期和时间 - ·  3 周前    · 
豪情万千的上铺  ·  mysql ...·  3 周前    · 
曾经爱过的松树  ·  批量 kill mysql ...·  3 周前    · 
忧郁的麻辣香锅  ·  海康SDK配置以及 ...·  10 月前    · 
大方的稀饭  ·  Element ...·  1 年前    · 
暴走的楼房  ·  SSL ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\xampp\htdocs\couriermanagement\database.php on line 15 [duplicate]

Ask Question Reference: What is variable scope, which variables are accessible from where and what are "undefined variable" errors? (3 answers)
Closed 2 years ago .

Notice: Undefined variable: dbConn in C:\xampp\htdocs\couriermanagement\database.php on line 15

Warning: mysqli_query() expects parameter 1 to be mysqli, null given in C:\xampp\htdocs\couriermanagement\database.php on line 15

Warning: mysqli_error() expects exactly 1 parameter, 0 given in C:\xampp\htdocs\couriermanagement\database.php on line 15

// database connection config $dbHost = 'localhost'; $dbUser = 'root'; $dbPass = ''; $dbName = 'courier_db'; $dbConn = mysqli_connect($dbHost, $dbUser, $dbPass, $dbName) or die ('MySQL connect failed. ' . mysqli_error($dbConn)); //mysqli_select_db($dbConn ,$dbName) or die('Cannot select database. ' . mysqli_error($dbConn));// function dbQuery($sql) $result = mysqli_query($dbConn,$sql) or die(mysqli_error()); return $result; function dbAffectedRows() global $dbConn; return mysqli_affected_rows($dbConn); function dbFetchArray($result, $resultType = MYSQL_NUM) { return mysqli_fetch_array($result, $resultType); function dbFetchAssoc($result) return mysqli_fetch_assoc($result); function dbFetchRow($result) return mysqli_fetch_row($result); function dbFreeResult($result) return mysqli_free_result($result); function dbNumRows($result) return mysqli_num_rows($result); function dbSelect($dbName) return mysqli_select_db($dbName); function dbInsertId() return mysqli_insert_id(); You have to supply two parameters , one for query and another for connection in mysqli_query($query,$conn) Suraj Khanal Oct 14, 2017 at 6:54 Either way you can call the query $result = mysqli_query($dbConn, $sql) Add connection to query or $result = $dbConn->query($sql); Check the doc Sivaraj S Oct 14, 2017 at 7:01 $result = $dbConn->query($sql); used this one but still getting error Notice: Undefined variable: dbConn in C:\xampp\htdocs\couriermanagement\database.php on line 15 Fatal error: Uncaught Error: Call to a member function mysqli_query() on null in C:\xampp\htdocs\couriermanagement\database.php:15 Stack trace: #0 C:\xampp\htdocs\couriermanagement\login.php(13): dbQuery('SELECT DISTINCT...') #1 {main} thrown in C:\xampp\htdocs\couriermanagement\database.php on line 15 Raj Singh Oct 14, 2017 at 7:16

it should look like this:

$dbConn = mysqli_connect("localhost", "my_user", "my_password", "world");
mysqli_query($dbConn, "SELECT * FROM test");

read:

http://php.net/manual/en/mysqli.query.php

under Procedural style

function dbQuery($sql) { global $dbconn; $result = mysqli_query($dbConn,$sql); } because try to access the variable which not defined in the function – Sivaraj S Oct 14, 2017 at 7:15 You have an error. mysqli_error() needs one argument. Please consider switching error mode on instead. How to get the error message in MySQLi? – Dharman Oct 30, 2019 at 22:00