Home > Database > Mysql Tutorial > 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
Release: 2024-11-27 10:57:09
Original
362 people have browsed it

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

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

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!

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