阿拉伯语文本存储为“???” [英] arabic text getting stored as "???"
本文介绍了阿拉伯语文本存储为“???”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我要做的是将阿拉伯语文本保存在My SQL中。
What I am trying to do is save the arabic text in My SQL.
我的SQL表的排序规则为 utf8_general_ci
My SQL Table has collation as utf8_general_ci
我在iPhone应用程序中有文本字段,我使用PHP保存数据。
I have textfield in iPhone app and I am saving data using PHP.
PHP代码看起来如下所示。
PHP Code looks like below.
$con = mysql_connect(localhost, $username, $password);
@mysql_select_db($database) or die("Unable to select database");
$propType = $_POST['propType'];
$price = $_POST['price'];
$type = $_POST['type'];
$zone = $_POST['zone'];
$location = $_POST['location'];
$no_floor = $_POST['no_floor'];
$no_apt = $_POST['no_apt'];
$basement = $_POST['basement'];
$area = $_POST['area'];
$addedBy = $_POST['addedBy'];
$imagePath = $_POST['imagePath'];
$saleType = $_POST['dummy001'];
$mauka = $_POST['mauka'];
$mobileNumForDial = "0";
$result = mysql_query("SELECT mobileNumber FROM userInfo WHERE username='$addedBy'");
while($data = mysql_fetch_row($result)){
$mobileNumForDial=$data[0];
}
$sql = mysql_query("INSERT INTO buildingData (propType, price, type, zone, location, no_floor,
no_apt, basement, area, addedBy, imagePath, dummy001, dummy002, mauka)
VALUES
('$propType', '$price', '$type', '$zone', '$location', '$no_floor', '$no_apt', '$basement',
'$area','$mobileNumForDial','$imagePath', '$saleType', '', '$mauka')");
iPhone代码如下所示
iPhone code looks like below
if ([btnImage.accessibilityIdentifier isEqualToString:@"no_image"]) {
imageSet = @"missing";
} else {
imageSet = @"set";
}
post = [[NSString alloc] initWithFormat:@"propType=%d&price=%@&type=%d&zone=%d&location=%d&no_floor=%d&no_apt=%d&basement=%d&area=%@&addedBy=%@&imagePath=%@&dummy001=%d&mauka=%@",
realEstatePV.selectedItem,
priceData.text,
typePV.selectedItem,
areaPV.selectedItem,
regionPV.selectedItem,
floorData.text.intValue,
aptData.text.intValue,
basementPV.selectedItem,
areaData.text,
[keychainItem objectForKey:kSecAttrAccount],
imageSet, salePV.selectedItem, mauka.text];
postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
postLength = [NSString stringWithFormat:@"%d", [postData length]];
url = [NSURL URLWithString:@"http://www.smart-kw.com/sama/saveBldgData.php"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
[theRequest setHTTPMethod:@"POST"];
[theRequest setValue:postLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPBody:postData];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if( theConnection )
{
indicator.hidden = NO;
[indicator startAnimating];
webData = [[NSMutableData data] retain];
}
else
{
NSLog(@"Internet problem maybe...");
}
问题是
<当我存储英文数据时,它很好。
The problem is
When I am storing english data, it is fine.
但是当我输入阿拉伯语文本时,它会被存储为???在mysql数据库中。
However when I type arabic text, it gets stored as ??? in mysql database.
知道为什么会这样吗?
我也试过以下,但数据仍然存储为 * ???
I also tried with below but still data is getting stored as *???
mysql_query("SET NAMES 'utf8'");
mysql_query('SET CHARACTER SET utf8');
$sql = mysql_query("INSERT INTO buildingData (propType, price, type, zone, location, no_floor,
no_apt, basement, area, addedBy, imagePath, dummy001, dummy002, mauka)
VALUES
('$propType', '$price', '$type', '$zone', '$location', '$no_floor', '$no_apt', '$basement',
'$area','$mobileNumForDial','$imagePath', '$saleType', '', '$mauka')");
推荐答案
尝试设置要使用UTF 8编码的postData而不是ASCII编码:
Try to set the postData to be encoded with UTF 8 instead of ASCII encoding:
postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
这篇关于阿拉伯语文本存储为“???”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文