Home  >  Article  >  Backend Development  >  Why Am I Getting the 'mysqli_query() Expects Parameter 1 to Be mysqli, Object Given' Error?

Why Am I Getting the 'mysqli_query() Expects Parameter 1 to Be mysqli, Object Given' Error?

Susan Sarandon
Susan SarandonOriginal
2024-11-26 03:27:18920browse

Why Am I Getting the

mysqli_query() Expects Parameter 1 to Be mysqli, Object Given

Error Context

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.

Solution

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn