2

我正在尝试将一些希伯来文文本从应用程序插入到 mysql 数据库,但这些值没有插入到数据库中。该方法适用于英语,但希伯来语文本有问题。它有时没有插入到数据库中,它显示了文本垃圾值。

目标C代码是

-(void)updateDatabase{

NSURL *url = [NSURL URLWithString:@"http://site.com/api/"];
AFHTTPClient *httpClient = [[AFHTTPClient alloc] initWithBaseURL:url];
NSDictionary *params = [[NSDictionary alloc] initWithObjectsAndKeys:image_name, @"image_name", invoice_no, @"invoice_no", photoReason, @"photo_reason", photoReasonText, @"photo_reason_text", txtField_1.text, @"user_info_1", txtField_2.text , @"user_info_2", txtField_3.text, @"user_info_3", txtField_4.text, @"user_info_4", txtField_5.text, @"user_info_5", txtField_6.text, @"user_info_6", txtField_7.text, @"user_info_7", nil];

NSLog(@"Params: %@", [params valueForKey:@"user_info_6"]);

NSMutableURLRequest *request = [httpClient requestWithMethod:@"POST" path:@"upload_info.php" parameters:params];

AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request];

[operation setUploadProgressBlock:^(NSInteger bytesWritten, long long totalBytesWritten, long long totalBytesExpectedToWrite) {
    NSLog(@"Sent %lld of %lld bytes", totalBytesWritten, totalBytesExpectedToWrite);
}];
[operation  setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {

    NSLog(@"success: %@", operation.responseString);

    SBJSON *parser = [[SBJSON alloc] init];
    NSMutableArray *statuses = [parser objectWithString:operation.responseString error:nil];
    int status = [[statuses valueForKey:@"status"] integerValue];
    if (status == 0) {
        invoice_no = [statuses valueForKey:@"invoice_no"];
        NSLog(@"Invoice No: %@", statuses);
        percentLabel.text = @"80%";
        [self pushView:4];

        [self pay];
    }

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Success" message:@"Card Images Are Uploaded." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    percentLabel.text = @"70%";

}
                                  failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                                      NSLog(@"error: %@",  operation.responseString);


                                      UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error..." message:operation.responseString delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
                                      [alert show];

                                  }];
[operation start];

}

而php代码是

<?php

include "constants.php";

$APIVersion = "1.0";
$commandName = $commandUploadInfo;

$image_name         = $_POST['image_name'];
$invoice_no         = $_POST['invoice_no'];
$photo_reason       = $_POST['photo_reason'];
$photo_reason_text  = $_POST['photo_reason_text'];
$user_info_1        = $_POST['user_info_1'];
$user_info_2        = $_POST['user_info_2'];
$user_info_3        = $_POST['user_info_3'];
$user_info_4        = $_POST['user_info_4'];
$user_info_5        = $_POST['user_info_5'];
$user_info_6        = $_POST['user_info_6'];
$user_info_7        = $_POST['user_info_7'];

$link = mysql_pconnect($dbhost, $dbuser, $dbpass)
or
die("{\"method\":\"".$commandName."\",".
    "\"version\":\"".$APIVersion."\",".
    "\"status\":-2,".
    "\"message\":\"Could not connect to database\",".
    "\"debug\":\"".mysql_error()."\"".
    "}");

mysql_select_db($dbname)
or
die("{\"method\":\"".$commandName."\",".
    "\"version\":\"".$APIVersion."\",".
    "\"status\":-2,".
    "\"message\":\"Could not select database\",".
    "\"debug\":\"".mysql_error()."\"".
    "}");


$insertSQL = "INSERT INTO ".
"`image_info2`(
 `image_name` ,
 `invoice_no` ,
 `photo_reason` ,
 `photo_reason_text` ,
 `user_info_1` ,
 `user_info_2` ,
 `user_info_3` ,
 `user_info_4` ,
 `user_info_5` ,
 `user_info_6` ,
 `user_info_7`
)".
"VALUES ('$image_name', '$invoice_no', '$photo_reason', '$photo_reason_text', '$user_info_1', '$user_info_2', '$user_info_3', '$user_info_4', '$user_info_5', '$user_info_6', '$user_info_7');";

mysql_query($insertSQL)
or
die("{\"method\":\"".$commandName."\",".
    "\"version\":\"".$APIVersion."\",".
    "\"status\":-2,".
    "\"message\":\"Failed to execute query\",".
    "\"debug\":\"".mysql_error()."\"".
    "}");

echo "{".
"\"method\":\"" . $commandName . "\",".
"\"version\":\"" . $APIVersion . "\",".
"\"status\":0,".
"\"id\":\"Info uploaded successfully\"".
"}";

?>

4

2 回答 2

1

您需要将包含希伯来文文本的列的排序规则设置为以下之一:

  • utf8_general_ci- 对于不区分大小写的匹配
  • utf8_general_cs- 对于区分大小写的匹配。

使用 PHP(垃圾文本)将希伯来文本插入 MySQL

于 2013-09-19T22:11:20.700 回答
0

我已经解决了我的希伯来语问题。这是一个数据库和表行/字段编码问题。这是我使用的解决方案。我从另一个答案中获得了帮助,下面给出了链接,以防有人需要。

  1. db 排序规则必须是utf8_general_ci.
  2. 表与希伯来语的排序规则必须是utf8_general_ci
  3. 在我的 php 连接脚本中,我放了header('Content-Type: text/html; charset=utf-8');
  4. 在我放的 xhtml 头标签中<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  5. 在我输入的连接脚本中选择数据库后mysql_query("SET NAMES 'utf8'");

然后问题就解决了。

第一个答案对我有帮助,我从那里拿走了

于 2013-09-21T04:11:10.330 回答