Home > Backend Development > PHP Tutorial > 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
Release: 2024-11-26 03:27:18
Original
948 people have browsed it

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
Copy after login

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);
Copy after login

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!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template