Home > Article > Backend Development > Why Am I Getting the 'mysqli_query() Expects Parameter 1 to Be mysqli, Object Given' Error?
When attempting to perform a database query, you may encounter the following error:
Warning: mysqli_query() expects parameter 1 to be mysqli, object given
This error occurs when the first parameter passed to the mysqli_query() function is not a valid MySQLi object.
The root cause of the issue lies in the fact that we are passing an instance of the createCon class to the mysqli_query function instead of the MySQLi connection object. The correct way to pass the connection is to use the myconn property of the createCon object:
$result = mysqli_query($connection->myconn, $query);
By accessing the $myconn property, we retrieve the actual MySQLi connection object, which is what the mysqli_query() function expects.
The above is the detailed content of Why Am I Getting the 'mysqli_query() Expects Parameter 1 to Be mysqli, Object Given' Error?. For more information, please follow other related articles on the PHP Chinese website!