0

我正在尝试使用 PHP 从 SQL 中的表中获取值列表

以这种方式执行了请求:

NSString *post = [NSString stringWithFormat:@"&Auth=%@", Auth];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d",[postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];

[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"path.php"]]];

[request setHTTPMethod:@"POST"];

[request setValue:postLength forHTTPHeaderField:@"Content-Length"];

[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Current-Type"];

[request setHTTPBody:postData];

NSURLResponse *response = nil;
NSError *error = nil;

NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];

NSString *Respuesta = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

这是我的 PHP 代码

    <?php
    $con=mysqli_connect("localhost","user","pass","dbname");
    // Check connection
    if (mysqli_connect_errno())
      {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
      }

    $result = mysqli_query($con,"SELECT * FROM DMARCAS");
        $cadena = "";
    while($row = mysqli_fetch_array($result))
      {
      $cadena .=  $row['U_DMarcaName'] . ", ";

      }
        echo $cadena;

    mysqli_close($con);
    ?>

在浏览器中正常工作,但在设备上我得到(空)

我正在运行测试,我认为错误发生在这一行:

如果我更改 $ 行 ['U_DMarcaName']。, "", 对于任何字符串之类的结果都是正确的。

谢谢你。

4

0 回答 0