Php 带标点符号的Sql查询
我的SQL数据库和Android应用程序之间有一个Web服务器。在数据库上,我想放一个带有问号的句子,但当Web服务器捕获查询时,echo为null。只有在短语中使用问号、点或逗号时才会出现这种情况。 Web服务器的代码为:Php 带标点符号的Sql查询,php,android,mysql,sql,json,Php,Android,Mysql,Sql,Json,我的SQL数据库和Android应用程序之间有一个Web服务器。在数据库上,我想放一个带有问号的句子,但当Web服务器捕获查询时,echo为null。只有在短语中使用问号、点或逗号时才会出现这种情况。 Web服务器的代码为: <?php $hostname_localhost ="*****"; $database_localhost ="*****"; $username_localhost ="*****"; $password_localhost ="*****"; $localho
<?php
$hostname_localhost ="*****";
$database_localhost ="*****";
$username_localhost ="*****";
$password_localhost ="*****";
$localhost = mysql_connect($hostname_localhost,$username_localhost,$password_localhost)
or
trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($database_localhost, $localhost);
$resultado = mysql_query('SELECT pregunta,respuesta,intentos,frase FROM Frases');
if (!$resultado) {
die('Consulta no válida: ' . mysql_error());
}
while ($fila = mysql_fetch_assoc($resultado)) {
$pregunta = $fila['pregunta'];
$respuesta = $fila['respuesta'];
$intentos = $fila['intentos'];
$frase = $fila['frase'];
}
mysql_close($localhost);
$data = array('pregunta' => $pregunta, 'respuesta' => $respuesta, 'intentos' => $intentos, 'frase' => $frase);
print (json_encode($data));
?>
在while循环中声明变量$pregunta、$respuesta、$intentos、$frase,一旦while循环完成,这些变量就不再存在 更改:
while ($fila = mysql_fetch_assoc($resultado)) {
$pregunta = $fila['pregunta'];
$respuesta = $fila['respuesta'];
$intentos = $fila['intentos'];
$frase = $fila['frase'];
}
mysql_close($localhost);
$data = array('pregunta' => $pregunta, 'respuesta' => $respuesta, 'intentos' => $intentos, 'frase' => $frase);
print (json_encode($data));
致:
然后,数据被分配到while循环之外的变量,并因此被保留,从而允许您输出json编码的数组。在java代码中,您可以通过这种方式发送GET变量。编码为utf-8
String query = URLEncoder.encode("Do I need to write a question mark?", "utf-8");
String url = "http://questionmark.com/search?q=" + query;
我想在翻译过程中有些东西丢失了。你说的“审讯”是什么意思?他可能是指问号,我不懂西班牙语,但在葡萄牙语中它们被称为问号,问号对不起,我猜jsonèU编码会中断,但我真的没有看到任何东西会中断它。你能找出空值是如何产生的吗?空值是指当我的查询中的短语有问号、点或任何特殊字符时
String query = URLEncoder.encode("Do I need to write a question mark?", "utf-8");
String url = "http://questionmark.com/search?q=" + query;