Mysqli_Query警告:mysqli_query()期望参数1为mysqli

Mysqli_Query警告:mysqli_query()期望参数1为mysqli 

我的代码中出现此错误,我不知道如何解决我的代码:


<?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中给出的资源


我做错了什么?


慕容森
浏览 1008回答 2
2回答

慕标5832272

你正在混合mysqli和mysql扩展,这将无法正常工作。你需要使用$myConnection=&nbsp;mysqli_connect("$db_host","$db_username","$db_pass")&nbsp;or&nbsp;die&nbsp;("could&nbsp;not&nbsp;connect&nbsp;to&nbsp;mysql");&nbsp;mysqli_select_db($myConnection,&nbsp;"mrmagicadam")&nbsp;or&nbsp;die&nbsp;("no&nbsp;database");mysqli与原始mysql扩展相比有许多改进,因此建议您使用mysqli。
打开App,查看更多内容
随时随地看视频慕课网APP