sql server - Cannot query correctly (MSSQL - PHP - JSON) -


i have little problem on project. , turns out query result returns nothing when value of first name or last name has 'ñ' in it.
here's code

config.php:

<?php    ini_set('mssql.charset', 'utf-8');    header('content-type: text/html; charset=utf-8');    $servername = "192.168.1.21"; /* ip add of db server */    $connection = array("database" => "db", "uid" => "?", "pwd" => "***");    $conn = sqlsrv_connect($servername, $connection);  if(!$conn){ echo "connection not established."; die(print_r(sqlsrv_errors(), true)); } ?> 

myquery:

$idnumber = $_post["idnum"]; $response = array(); $query2 = "select clname, cfname, cmname, cqualifier student cidno = '$idnumber'";  try{     $stmt2 = sqlsrv_query($conn, $query2); } catch(pdoexeption $ex){     $response["success"] = 0;     $response["message"] = "database error!";     die(json_encode($response)); } $row2 = sqlsrv_fetch_array($stmt2, sqlsrv_fetch_assoc);      if($row2){         $response["success"] = 1;         $response["message"] = "data available";         $last_name = $row2["clname"];         $first_name = $row2["cfname"];         $qualify = $row2["cqualifier"];          $first_name = html_entity_decode(htmlentities($first_name));         $last_name = html_entity_decode(htmlentities($last_name));          $name = $first_name." ".$last_name." ".$qualify;          $response["name"] = $name;          echo json_encode($response);     }      else{         $response["success"] = 0;         $response["message"] = "database error!";         die(json_encode($response));     } 

i looked on these pages: 1, 2, 3, etc.

but don't have clue why happening program.

example in databases: clname = "española", cfname = "edgar", cqualifier = "jr."
output: "name":"edgar jr."
while: clname = "agustin", cfname = "florence", cqualifier = "jr."
output: "name":"florence agustin jr."

ideas? please?

note: not authorized alter or change on database.

i think encoding error mssql con doest not in utf-8 mode,

what did if following iso-8859-1 endoced, , utf8_encode missing output op got, utf8_encode correct

<?php   $row = ['clname' => "española", 'cfname' => "edgar", 'cqualifier' => "jr."];  $last_name  = utf8_encode($row["clname"]); $first_name = $row["cfname"]; $qualify    = $row["cqualifier"];  $first_name = html_entity_decode(htmlentities($first_name)); $last_name = html_entity_decode(htmlentities($last_name));  $name = $first_name." ".$last_name." ".$qualify;  $response["name"] = $name; $enc = json_encode($response,json_unescaped_unicode);  print_r($name); print_r($response); print_r($enc); 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -