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!