2017-04-20 350 views
0

我在连接数据库时遇到问题。请帮助这个代码错了什么?连接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>"; 
    } 
} 
?> 
+2

有什么错误 – clearshot66

+0

为什么你认为* *的东西是错误的代码?你想要解决什么实际问题? – David

+0

如果你有连接问题检查错误,http://php.net/manual/en/mysqli.connect-error.php。 – chris85

回答

1

您正在访问的$row_cats - 阵列和$row_brands - 阵列错误。

使用[],而不是()