2

我的 MySQL 数据库设置为 utf8_unicode_ci 并且我将 $pdo->exec('SET NAMES "utf8"') 作为以下 php 代码的一部分,但是当我从查询中回显文本时使用连字符 - 看起来像这样 –。我在做什么错,为什么连字符显示不正确?

<?php    
    try {
        $pdo = new PDO('mysql:host=localhost;dbname=danville_tpf', 'danville_dan', 'password');
        $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $pdo->exec('SET NAMES "utf8"');
    } catch (PDOException $e) {
        $output = 'Unable to connect to the database server.';
        include 'output.html.php';
        exit();
    }

    $output = 'Theme Park Database initialized';
    //include 'output.html.php';//

    try {
        $park_id = $_GET['park_id'];
        $query = "SELECT * FROM tpf_parks WHERE park_id = $park_id";
        $result = $pdo->query($query);
    } catch (PDOException $e) {
        $output = 'Unable to connect to the database server.';
        //include 'output.html.php';//
    }

    $output = 'Sucessfully pulled park';
    //include 'output.html.php';//

    foreach ($result as $row) {
        $parkdetails[] = array(
            'name' => $row['name'],
            'blurb' => $row['blurb'],
            'website' => $row['website'],
            'address' => $row['address'],
            'logo' => $row['logo']
        );    
    }
?>

请帮忙。

4

1 回答 1

10
于 2013-03-29T00:33:29.097 回答