0

I have a MySQL database hosted on a server. On table PERSON, I have the NAME column. One of the rows, has a name with the character "Ñ".

I'm working with a PHP Webservice that returns all the rows of that table, it works fine, but when one of the values contains a "Ñ", it returns null.

For Example: TABLE: Person. (ID - NAME) 1 - John 2 - Paul 3 - Iñaki

The PHP webservice returns Johm, Paul and null.

If I connect to the database from SQLyog or other software, I see the real values, John, Paul and Iñaki, so the problem is when the PHP Service returns the values of the table.

This is the PHP:

<?php
header('Content-type: application/json');


$server = "*****";
$username = "******";
$password = "********";
$database = "********";

$con = mysql_connect($server, $username, $password) or die ("Could not connect: " . mysql_error());
mysql_select_db($database, $con);

$sql = "SELECT * FROM person";
$result = mysql_query($sql) or die ("Query error: " . mysql_error());

$records = array();

while($row = mysql_fetch_assoc($result)) {
    $records[] = $row;
}

mysql_close($con);

echo $_GET['jsoncallback'] . '(' . json_encode($records) . ');';
?>

Any help?

Teodor Talov
  • 1,933
  • 2
  • 25
  • 39
Agustín
  • 1,546
  • 7
  • 22
  • 41
  • did you tell your client what charset you've encoded everything in? you have to use the SAME charset throughout, or connect individual stages with appropriate charset translation logic. – Marc B Feb 06 '14 at 22:51
  • 1
    possible duplicate of [json\_encode is returning NULL?](http://stackoverflow.com/questions/1972006/json-encode-is-returning-null) – Class Feb 06 '14 at 22:52
  • yea! it was that! thanks! I guess I gotta start doin better researches, ha? – Agustín Feb 06 '14 at 23:10

0 Answers0