我有一个 MySQL 数据库,其中包含带有诸如 andreá 之类的口音的西班牙语单词。
我正在使用它,它显示正常:
<?php
include "../BD/conexion.php";
mysql_query('SET NAMES utf8');
class Faq
{
public $pregunta;
public $respuesta;
public function __construct($pregunta,$respuesta)
{
$this->pregunta = $pregunta;
$this->respuesta = $respuesta;
}
public static function get()
{
$rows = array();
$res = mysql_query('SELECT * FROM Faq');
while ($row = mysql_fetch_array($res)) {
$rows[] = $row;
}
function filter(&$value) {
$value = htmlspecialchars($value, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
}
array_walk_recursive($rows, "filter");
return $rows;
}
当我在 html 中打印行时,它显示得很好,如下所示:
但我试图更改为新的 mysqli_ 函数,如下所示:
<?php
$conexion = mysqli_connect("localhost","root","","prueba2");
mysqli_query($conexion,'SET NAMES utf8');
mysqli_close($conexion);
class Faq
{
public $pregunta;
public $respuesta;
public function __construct($pregunta,$respuesta)
{
$this->pregunta = $pregunta;
$this->respuesta = $respuesta;
}
public static function get()
{
$conexion = mysqli_connect("localhost","root","","prueba2");
$rows = array();
$res = mysqli_query($conexion,'SELECT * FROM Faq');
while ($row = mysqli_fetch_array($res)) {
$rows[] = $row;
}
function filter(&$value) {
$value = htmlspecialchars($value, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8');
}
array_walk_recursive($rows, "filter");
return $rows;
mysqli_close($conexion);
return $rows;
}
当我展示它时,我得到:
我尝试使用 mysqli_set_charset($conexion, "utf8")
但它具有相同的输出...帮助=(