PHP   发布时间:2022-04-04  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了php-阿拉伯文本存储为“ ???”大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在尝试将阿拉伯文本保存在My sql中.

我的sql表的排序规则为utf8_general_ci

我在iPhone应用程序中有文本字段,并且正在使用PHP保存数据.

PHP代码如下所示.

$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代码如下所示

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=%@@R_874_7231@ummy001=%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 sethttpR_966_11845@ethod:@"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...");
}

问题是

当我存储英语数据时,这很好.

但是,当我输入阿拉伯文字时,它会被存储为???.在MysqL数据库中.

知道为什么会这样吗?

编辑1

我也在下面尝试过,但仍然将数据存储为* ???

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')");

解决方法:

尝试将postData设置为使用UTF 8而不是ASCII编码进行编码:

postData = [post dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];

大佬总结

以上是大佬教程为你收集整理的php-阿拉伯文本存储为“ ???”全部内容,希望文章能够帮你解决php-阿拉伯文本存储为“ ???”所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: