Encoding SQL_Latin1_General_CP1_CI_AS into UTF-8

后端 未结 7 1920
小鲜肉
小鲜肉 2020-12-09 10:50

I\'m generating a XML file with PHP using DomDocument and I need to handle asian characters. I\'m pulling data from the MSSQL2008 server using the pdo_mssql driver and I app

7条回答
  •  生来不讨喜
    2020-12-09 11:17

    You can try so:

    header("Content-Type: text/html; charset=utf-8");
    $dbhost   = "hostname";
    $db       = "database";
    $query = "SELECT *
        FROM Estado
        ORDER BY Nome";
    $conn = new PDO( "sqlsrv:server=$dbhost ; Database = $db", "", "" );
    $stmt = $conn->prepare( $query, array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED, PDO::SQLSRV_ENCODING_SYSTEM) );
    $stmt->execute();
    while ( $row = $stmt->fetch( PDO::FETCH_ASSOC ) )
    {
    // CP1252 == code page Latin1
    print iconv("CP1252", "ISO-8859-1", "$row[Nome] 
    "); }

提交回复
热议问题