Mysqli_Query警告:mysqli_query()期望参数1为mysqli [英] Mysqli_Query warning: mysqli_query() expects parameter 1 to be mysqli
本文介绍了Mysqli_Query警告:mysqli_query()期望参数1为mysqli的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的代码中出现此错误,我不知道如何解决我的代码:
I got this error in my code and I don't know how to solve it my code:
<?php
session_start();
include_once"connect_to_mysql.php";
$db_host = "localhost";
// Place the username for the MySQL database here
$db_username = "root";
// Place the password for the MySQL database here
$db_pass = "****";
// Place the name for the MySQL database here
$db_name = "mrmagicadam";
// Run the actual connection here
$myConnection= mysql_connect("$db_host","$db_username","$db_pass") or die ("could not connect to mysql");
mysql_select_db("mrmagicadam") or die ("no database");
$sqlCommand="SELECT id, linklabel FROM pages ORDER BY pageorder ASC";
$query=mysqli_query($myConnection, $sqlCommand) or die(mysql_error());
$menuDisplay="";
while($row=mysql_fetch_array($query)) {
$pid=$row["id"];
$linklabel=$row["linklabel"];
$menuDisplay='<a href="index.php?pid=' .$pid . '">' .$linklabel. '</a><br/>';
}
mysqli_free_result($query);
?>
这是错误:
警告:mysqli_query()期望参数1为mysqli,在第17行的C:\ xampp \ htdocs \ limitless \ connect_to_mysql.php中给出的资源
Warning: mysqli_query() expects parameter 1 to be mysqli, resource given in C:\xampp\htdocs\limitless\connect_to_mysql.php on line 17
我做错了什么?
推荐答案
您正在混合 mysqli 和 mysql 扩展名,将无法使用.
You are mixing mysqli and mysql extensions, which will not work.
您需要使用
$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");
mysqli
与原始mysql
扩展名相比有很多改进,因此建议您使用mysqli
.
mysqli
has many improvements over the original mysql
extension, so it is recommended that you use mysqli
.
这篇关于Mysqli_Query警告:mysqli_query()期望参数1为mysqli的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文