PHP foreach-从数据库显示

您好,我尝试使用foreach循环显示数据库中的记录,但是不起作用, 我打算用来在prestashop的自定义页面中显示记录,

<?php
$servername = "localhost";
$database = “My_database”;
$username = “My_user”;
$password = “pass”;

// Create connection
$conn = mysqli_connect($servername, $username, $password, $database);
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";

$sql = "SELECT id, name, product, reference  FROM test_customer";
$result = $conn->query($sql);


foreach ($test_customer as $user)
{
    echo $user['id'].' - '.$user[‘name’].’ - '.$user[‘product’].’ - '.$user[‘reference’].’<br>';
}


mysqli_close($conn);

?>

评论