Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I am currently working in an iOS application that requires this same functionality. For mySQL database queries on the server, I am using server-side PHP scripts that can accept variables, such as the table name or database search term. </p> <p>What I do is I make an HTTP GET request using objective-C's NSMutableURLRequest, then have the server process the request (in PHP), and then return the database query results to my application in JSON format. I use <a href="https://github.com/stig/json-framework/" rel="nofollow">SBJsonParser</a> to parse the returned data into an NSData, and then an NSArray object.</p> <p>An example of making an HTTP request in Objective-C:</p> <pre><code>NSString *urlString = [NSString stringWithFormat:@"http://website.com/yourPHPScript.php?yourVariable=something"]; NSURL *url = [NSURL URLWithString: urlString]; NSMutableURLRequest *request1 = [[NSMutableURLRequest alloc] initWithURL:url]; /* set the data and http method */ [request1 setHTTPMethod:@"GET"]; [request1 setHTTPBody:nil]; /* Make the connection to the server with the http request */ [[NSURLConnection alloc] initWithRequest:request1 delegate:self]; </code></pre> <p>There is more code that you need to add to actually respond to the request when it returns, and I can post an example of that if you would like.</p> <p>I actually dont know if this is the best way to do this, but It has worked for me so far. It does require that you know PHP though, and I don't you if you have any experience with it.</p> <hr> <p>UPDATE:</p> <p>Here is some sample code showing how to respond to the request. In my case, since I am getting a JSON encoded response, I use the SBJsonParser to parse the response.</p> <pre><code>- (void)connectionDidFinishLoading:(NSURLConnection *)connection { /* This string contains the response data. * At this point you can do whatever you want with it */ NSString *responseString = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding]; /* Here I parse the response JSON string into a native NSDictionary using an SBJsonParser */ SBJsonParser *parser = [[[SBJsonParser alloc] init] autorelease]; /* Parse the JSON into an NSDictionary */ NSDictionary *responseArr = [parser objectWithString:responseString]; /* Do whatever you want to do with the response */ /* Relsease the connection unless you want to re-use it */ [connection release]; } </code></pre> <p>Also add these methods, assuming you have an NSMUtableData instance variable titled receivedData.</p> <pre><code>- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response { [receivedData setLength:0]; } - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data { [receivedData appendData:data]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload