I managed to connect to the MySQL database in my application and use the C API, which is almost exactly similar to the PHP commands (mysql_real_connect (), mysql_query (), mysql_fetch_array (), etc.) and which I pretty I just don't know how to return a data request. I use an array or a dictionary, and then how to parse it. For example, in PHP, I would do something like this (after connecting):
$results = mysql_query("SELECT * FROM theDatabase"); if (mysql_num_rows($results) > 0) { while($row = mysql_fetch_array($results)) { print $row; } }
What would be the equivalent of objective-c? Thanks.
Edit:
OK, so I made some progress - I can make a request and get the number of fields / rows returned, I just canβt access the data itself. Here is my code that I sewed along with the MySQL docs and several other sites:
- (IBAction)dbConnect:(id)sender { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; MYSQL mysql; mysql_init(&mysql); if (!mysql_real_connect(&mysql, "10.1.1.99", "******", "******", "oldphotoarchive", 0, NULL, 0)) { NSLog(@"%@", [NSString stringWithUTF8String:mysql_error(&mysql)]); } else { MYSQL_RES *result; MYSQL_ROW row; unsigned int num_fields; unsigned int num_rows; unsigned long *lengths; if (mysql_query(&mysql,"SELECT * FROM photorecord")) {
source share