doushui3061 2014-10-31 07:41
浏览 61
已采纳

如何将PHP mysql_fetch_array()转换为NSMutableArray? PHP - > Xcode

I'm trying to read an entire row from mysql into a NSMutableArray using PHP.

Example PHP Code

<?php
$con = mysql_connect("localhost", "username", "password");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

$db_selected = mysql_select_db("test_db",$con);
$sql = "SELECT * from Person WHERE Lastname='smith'";
$result = mysql_query($sql,$con);
echo(mysql_fetch_array($result));

mysql_close($con);
?>

The output of the array above could be:

Array
(
[0] => smith
[LastName] => smith
[1] => Adam
[FirstName] => Adam
[2] => California
[Address] => California
[3] => 22
[Age] => 22
)

How do I read that array from mysql, and store that as a NSMutableArray?

So far, I only know how to receive a string from PHP using the following:

//to execute php code
NSData *dataURL = [NSData dataWithContentsOfURL: [NSURL URLWithString:strURL]];

//to receive the returned value
NSString *strResult = [[NSString alloc] initWithData:dataURL encoding: NSUTF8StringEncoding];

But I don't know how to read an array and convert that into a NSMutableArray. I spent hours searching and I cannot find an answer. I would prefer not to use JSON and stick with Mysql/PHP/Obj-c.

  • 写回答

1条回答 默认 最新

  • douqian6315 2014-10-31 08:47
    关注

    It is not so simply eheh. You have to transform the HTML data in something that iOS can understand. Of course, if you do the var_dump() of the $result array is not something that iOS can understand! You have to convert the string in a universal format like JSON or XML, and then download the data. So, when iOS receive the JSON/XML, you can handle it using reflection or something else to reproduce the JSON objects.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 平板录音机录音问题解决
  • ¥15 请问维特智能的安卓APP在手机上存储传感器数据后,如何找到它的存储路径?
  • ¥15 (SQL语句|查询结果翻了4倍)
  • ¥15 Odoo17操作下面代码的模块时出现没有'读取'来访问
  • ¥50 .net core 并发调用接口问题
  • ¥15 网上各种方法试过了,pip还是无法使用
  • ¥15 用verilog实现tanh函数和softplus函数
  • ¥15 Hadoop集群部署启动Hadoop时碰到问题
  • ¥15 求京东批量付款能替代天诚
  • ¥15 slaris 系统断电后,重新开机后一直自动重启