将php连接到mysqli数据库错误

时间:2017-04-20 18:35:54

标签: php mysqli

我在将此与数据库连接时遇到问题。请帮忙解释这段代码有什么问题?

<?php
$con = mysqli_connect('localhost','root','','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>";
    }
}
//getting the brands
function getBrands(){
    global $con;
    $get_brands="select * from brands";
    $run_brands=mysqli_query($con, $get_brands);
    while($row_brands = mysqli_fetch_array($run_brands)){
        $brand_id=$row_brands('brand_id');
        $brand_title=$row_brands('brand_title');
        echo "<li><a href='#'>$brand_title</a></li>";
    }
}
?>

1 个答案:

答案 0 :(得分:1)

您正在访问$row_cats - 数组和$row_brands - 数组错误。

使用[]代替()