警告:非法字符串偏移PHP Mysqli

时间:2017-06-12 01:06:07

标签: php mysql mysqli

我试图使用以下代码从mysql数据库中获取数据:

$con = mysqli_connect('localhost', 'root', '', 'nicu');
    mysqli_query($con, "set NAMES utf8");
    $query = mysqli_query($con, "select * from user");
    while($rows = mysqli_fetch_assoc($query)) :
        $rows = $rows["nicuAddress"];
        $address = $rows["nicuEmail"];
        echo "$rows<br>$address";
    endwhile;

但每次我运行此代码时都会收到此警告:Warning: Illegal string offset

我需要做些什么改变才能解决这个问题?

1 个答案:

答案 0 :(得分:2)

您正试图到达被覆盖的数组的一部分。运行$address = $rows["nicuEmail"]后,您无法作为数组访问$address = $rows["nicuAddress"]; // <-- Change to address $email = $rows["nicuEmail"]; // <-- Change to email echo "$address<br>$email";

<强>解决方案

README.md