Home  >  Article  >  Database  >  Why am I getting a 'Warning: mysqli_query() expects parameter 1 to be mysqli, resource given' error?

Why am I getting a 'Warning: mysqli_query() expects parameter 1 to be mysqli, resource given' error?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-27 10:57:09310browse

Why am I getting a

Warning: mysqli_query() Parameter Error Resolved

Encountering the warning "Warning: mysqli_query() expects parameter 1 to be mysqli, resource given" typically indicates a mismatch between the mysqli and mysql extensions. Here's how to resolve it:

In your code, you've inadvertently mixed mysqli and mysql extensions. To fix this, ensure consistency throughout your script. Replace the following lines with their mysqli equivalents:

$myConnection= mysql_connect("$db_host","$db_username","$db_pass") or die ("could not connect to mysql");
mysql_select_db("mrmagicadam") or die ("no database");  

With:

$myConnection= mysqli_connect("$db_host","$db_username","$db_pass") or die ("could not connect to mysql");

mysqli_select_db($myConnection, "mrmagicadam") or die ("no database");   

By switching to mysqli functions, you take advantage of its improved capabilities and resolve the error. Remember, maintain consistency between the mysqli and mysql extensions throughout your code.

The above is the detailed content of Why am I getting a 'Warning: mysqli_query() expects parameter 1 to be mysqli, resource 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