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
.