我在数据库中有包含特殊字符的单词(主要是西班牙语,如波浪号).在数据库中,所有内容都保存并使用PHPmyAdmin正确显示,但是当我获取数据(使用PHP)并在浏览器中显示时,我得到一个奇怪的字符,如"?" 有一个正方形...我需要一个通用的修复,所以我不需要每次都逃避每个字符,而且我也可以将PHP格式的特殊西班牙语字符插入到数据库中...
HTML是正确的:
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
Run Code Online (Sandbox Code Playgroud)
所有表和数据库都设置为utf8_spanish
我得到的角色:
有什么建议???
谢谢!!!
我有一个简单的SQL查询问题:
SELECT a.idElemento, b.nombre, b.descripcion
FROM productos_elementos a
INNER JOIN elementos_adicionales b
ON a.idElementoAdicional=b.id_elemento_adicional
INNER JOIN precio_elemento c
ON a.idElemento=c.idElemento
WHERE a.idProducto = 1 AND c.idPolitica = 1
Run Code Online (Sandbox Code Playgroud)
当我在数据库上执行此查询时,它返回:
IdElemento Nombre Descripcion
1 p1 p1_desc
2 p2 p2_desc
Run Code Online (Sandbox Code Playgroud)
但是我的PHP代码向我返回了以下值:
IdElemento Nombre Descripcion
1 null null
2 null null
Run Code Online (Sandbox Code Playgroud)
我不知道为什么会这样。有任何想法吗?这是代码:
//$query is a string with the querty: SELECT....
$result = $this->conn->query($query);
$aux = $result->fetchAll(PDO::FETCH_OBJ);
$results_to_send = json_encode($aux);
Run Code Online (Sandbox Code Playgroud)
如果此时我打印$ variable $ results_to_send,它将被初始化为:
[{"idElemento":"1","nombre":null,"descripcion":null},{"idElemento":"2","nombre":null,"descripcion":null}]
Run Code Online (Sandbox Code Playgroud)
我在这段代码中使用值:
foreach ($results_to_send as $key => $value){
...
echo …Run Code Online (Sandbox Code Playgroud)