แทรกข้อความภาษาไทยบน android ผ่าน php webvice มาเก็บไว้ที่ sql database ข้อความที่ได้เป็น ?????? รบกวนผู้รู้ตอบหน่อยครับ !!
แทรกข้อความภาษาไทยบน android ผ่าน php webvice มาเก็บไว้ที่ sql database ข้อความที่ได้เป็น ?????? แบบนี้ครับ
ด้านล่างเป็นโค้ด PHP webservice ครับ
Code (PHP)
<?php
require_once("lib/nusoap.php");
//Create a new soap server
$server = new soap_server();
$objConnect = mssql_connect("ITUCHKUB-PC", "sa", "aa") or die("Error Connect to Database");
$objDB = mssql_select_db("Medical_Records");
//Define our namespace
$namespace = "https://www.thaicreate.com/android/WebServiceServer.php";
$server->wsdl->schemaTargetNamespace = $namespace;
//Configure our WSDL
$server->configureWSDL("HelloWorld");
// Register our method and argument parameters
$BorrowOPD = array(
'HN' => "xsd:string",
'department' => "xsd:string",
'check_R,' => "xsd:string",
'name_B,' => "xsd:string",
'position_b,' => "xsd:string",
);
$ReturnOPD = array(
'HN' => "xsd:string",
'name_r,' => "xsd:string",
'position_r,' => "xsd:string",
);
$server->register('BorrowOPD', $BorrowOPD, array('return' => 'xsd:string'));
$server->register('ReturnOPD', $ReturnOPD, array('return' => 'xsd:string'));
function BorrowOPD($HN, $department, $check_R, $name_B, $position_b) {
$strSQL = "SELECT [HN],[FIRSTNAME],[LASTNAME] FROM PATIENT_NAME WHERE HN = '$HN'";
$objQuery = @mssql_query($strSQL);
$objSelect = @mssql_fetch_array($objQuery);
if (!$objSelect) {
$state = "not found";
} else {
$Tim = date("H:i");
$da = date("d/m/Y");
$strSQL2 = "SELECT * FROM OPD_LogBR WHERE HN = '$HN' AND date_R IS NULL";
$objQuery2 = @mssql_query($strSQL2);
$objSelect2 = @mssql_fetch_array($objQuery2);
if (!$objSelect2) {
$HN = "$objSelect[HN]";
$name = "$objSelect[FIRSTNAME]";
$sername = "$objSelect[LASTNAME]";
$Tim = date("H:i");
$da = date("d/m/Y");
$strSQL = "INSERT INTO OPD_LogBR (HN,name,sername,department,check_R,date_b,time_b,name_borrow,position_b) VALUES ('$HN','$name','$sername','$department','$check_R','$da','$Tim','$name_B','$position_b')";
$objInsert = @mssql_query($strSQL);
$state = "Record inserted";
} else {
$state = "Record already";
}
}
return $state;
}
function ReturnOPD($HN, $name_R, $position_R) {
$strSQL = "SELECT * FROM OPD_LogBR WHERE HN = '$HN' AND date_R IS NULL";
$objQuery = @mssql_query($strSQL);
$objSelect = @mssql_fetch_array($objQuery);
if (!$objSelect) {
$state = "not found";
} else {
$Tim = date("H:i");
$da = date("d/m/Y");
$strSQL2 = "UPDATE OPD_LogBR SET date_r='$da',time_r='$Tim',name_return='$name_R',position_r='$position_R' WHERE HN = '$HN'";
$objUpdate = @mssql_query($strSQL2);
$state = "Record Update";
}
return $state;
}
// Get our posted data if the service is being consumed
// otherwise leave this data blank.
$POST_DATA = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : '';
// pass our posted data (or nothing) to the soap service
$server->service($POST_DATA);
exit();
?>
Tag : Mobile, Android, JAVA
Date :
2014-09-13 00:11:56
By :
ituchkub
View :
1036
Reply :
2
ในส่วนของ Database แนะนำให้่เก็บเป็นแบบ NVarchar ครับ
Code (PHP)
$server->soap_defencoding = 'UTF-8';
$server->decode_utf8 = false;
$server->encode_utf8 = true;
ส่วนของ Android ควรส่งเป็นแบบ UTF-8 ด้วยครับ
Code (Android-Java)
httppost.setHeader("Accept-Charset","utf-8");
Date :
2014-09-14 09:53:46
By :
mr.win
Load balance : Server 00