PHP MySQL & vs&问题

在数据库表中,列name是varchar(255)


列上的编码:utf8_unicode_ci


列中的示例值:Garner Heating & Cooling


当我查询这个值时,使用:


$conn = new mysqli($host, $user, $pw, $db);

$sql = "SELECT id,name FROM bizs WHERE name = 'Garner Heating & Cooling'";

if ($result = $conn->query($sql)) {


     if ($conn->affected_rows > 0) {

        while ($row = $result->fetch_assoc()) {

            echo "OLD Name: " . $row['name'] . "\n";

        }

     }


}

输出: OLD Name: Garner Heating & Cooling


为什么&被转换为&?


猛跑小猪
浏览 96回答 2
2回答

倚天杖

使用这一行来查看相同的编码数据:echo "OLD Name: " . htmlentities($row['name'], ENT_QUOTES) . "\n";

红颜莎娜

您应该使用 htmlentities 功能:$conn = new mysqli($host, $user, $pw, $db);$sql = "SELECT id,name FROM bizs WHERE name = 'Garner Heating & Cooling'";if ($result = $conn->query($sql)) {     if ($conn->affected_rows > 0) {        while ($row = $result->fetch_assoc()) {           echo "OLD Name: " . htmlentities($row['name'], ENT_QUOTES) . "\n";        }     }}
打开App,查看更多内容
随时随地看视频慕课网APP