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 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果