语法错误,意外' $ query' (T_VARIABLE)

时间:2017-12-29 10:23:14

标签: mysql

$koneksi = mysqli_connect($host_name, $username, $password, $database);

$query = mysqli_query($koneksi, "SELECT * FROM pembeli");
$hasil = mysqli_query($query);

while ( $buyer = mysqli_fetch_assoc($hasil)){
    echo $buyer ['Nama'];
    echo $buyer ['Barang'];
    echo $buyer ['Retribusi'];
}

我有那行代码,它的生成语法错误意外' $ query'(T_VARIABLE)。怎么了 ?

1 个答案:

答案 0 :(得分:1)

在mysqli中无需写: - mysql_select_db($database);

因为第四个参数是数据库名称

示例: - mysqli_connect($localhost, $username, $password, $database);

更新您的代码,如下所示

$database  = "jaka_crud_ci";

$koneksi = mysqli_connect($host_name, $username, $password, $database);

$query = mysqli_query($koneksi, "SELECT * FROM pembeli");

while ( $buyer = mysqli_fetch_assoc($query)){
    echo $buyer['Nama'];
    echo $buyer['Barang'];
    echo $buyer['Retribusi'];
}