警告:mysqli_query() 期望参数 1 是 mysqli,资源给定 [英] Warning: mysqli_query() expects parameter 1 to be mysqli, resource given
本文介绍了警告: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,资源在 C:\xampp\htdocs\limitless\connect_to_mysql.php 第 17 行
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() 期望参数 1 是 mysqli,资源给定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文