<?php
$con = mysqli_connect("localhost","root"," Yes","ecommerce");
//getting the categories
function getCats(){
global $con;
$get_cats = "select * from categories";
$run_cats = mysqli_query($con, $get_cats);
while($row_cats=mysqli_fetch_array($run_cats)){
$cat_id = $row_cats['cat_id'];
$cat_title = $row_cats['cat_title'];
echo "<li><a href= "#">$cat_title</a></li>";
;}
}
?>
错误:
警告:mysqli_query()要求参数1为mysqli,第16行的C:\ Xampp \ htdocs \ ecommerce \ functions \ functions.php中给出布尔值
答案 0 :(得分:0)
检查您的连接查询密码,尝试遵循代码..我的事情空间有问题。
<?php
$con = mysqli_connect("localhost","root","Yes","ecommerce") or die("Not connected.");
//getting the categories
function getCats(){
global $con;
$get_cats = "select * from categories";
$run_cats = mysqli_query($con, $get_cats);
while($row_cats=mysqli_fetch_array($run_cats)){
$cat_id = $row_cats['cat_id'];
$cat_title = $row_cats['cat_title'];
echo "<li><a href= '#'>$cat_title</a></li>";
}
}
?>
答案 1 :(得分:0)
我只是用我的数据库连接检查你的代码,但它正在工作!正确检查数据库连接。
将die
添加到DB
连接。
$con = mysqli_connect("localhost","user_name","password","db_name") or die("Not connected.");
答案 2 :(得分:-4)
人们在mysqli中犯的最愚蠢的错误是
mysqli_query($con,"SELECT * FROM Persons");
。他们忘了变量:
$ CON 或者请与我们分享您的代码。也许我们可以在那之后找到错误解决方案。