Article written by

31 Responses

Page 1 of 1
  1. ing conti
    ing conti at |

    can be a very simple example, but lacks a lot of features need to work decently
    Apart form error checking in PHP, synch download in IOS is the evil.. apple says.
    Feel free to contact me if You need further  details.

  2. admin
    admin at |

    Hi Mr. conti,
    this is only a sample, it’s not the bible.
    I want only to give some info for beginners.
    Also, remeber that Apple is a great company its guidelines are very useful but Apple is a company, Apple wants to drive developers to Apple’s goals.
    Anyway this blog is open, so if you want you can post your articles (I’ll put your name and a link to your site) or you can reply to this post.
    Have a good day,
    Gg1

  3. Julius
    Julius at |

    Mr Conti, could you elaborate why retrieving data this way is evil? Im a beginner and would like to know further detail. Also, how do you ensure data delivery whilst not overloading the server If many users are downloading the data at once?

  4. webcoderph
    webcoderph at |

    Hi
    after getting the result from the database. how would you display the result? i mean what class is the right to use? is it uitable view? im a professional web developer using php and ruby but im a new  on ios :D
    i just want to understand what the class is the right to use with the response from a database. 
    thanks and more power

  5. admin
    admin at |

    Hi,
    It depends on what you are doing, if you are retrieving a dump of the db, you cold put it into a uitextview.
    If you are retrieving a list of users, you should put it into a uitableview, if you are getting data about aircrafts you should place each flying object in a mkmapview.

  6. warner
    warner at |

    i have an error that strResult is an unused variable:(

  7. admin
    admin at |

    Strange, you should have a warning. Ant it is normal, you have only set its value, so it is unused.
    If you try to print it the warning will go away.
    For example add the following line:
    NSLog(“%@”, strResult);
    after
    NSString *strResult = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

  8. Charles
    Charles at |

    After pasting your code, I get this error:
    Use of undeclared identifier 'data'
    How do I fix this issue?

  9. Charles
    Charles at |

    The error is in this line of code
     
     NSString *strResult = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];

  10. admin
    admin at |

    @Charles make sure you have added the following line before the error

     

    NSData      *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&e];


  11. Charles
    Charles at |

    Thanks! Worked like a charm.

  12. Charles
    Charles at |

    I want to take the *strResult and populate a TableView with it. Can you give me some pointers?

  13. admin
    admin at |
  14. Charles
    Charles at |

    It is giving me a Bad Gateway 502 error. Will have to check this ayer once they get it fixed. Thanks again!

  15. admin
    admin at |
  16. Charles
    Charles at |

    Both of those links are dead. :-( How can I go about using the strResult variable? Id like to plug it into a Table View or a drop down menu.

  17. Juninho De Luca/Brazil
    Juninho De Luca/Brazil at |

    Man… tyvm…
    I have no idea how many time i have looking for a simple sample about to use PHP as layer to connect with remote MySQL.
    Thks again!

  18. Fetom
    Fetom at |

    Hi,

    I have found a simple solution for your problem. I tried the sqlgw package from
    http://www.sqlgw.com

    and it works fine.

  19. admin
    admin at |

    It’s java….
    It costs a tot….
    I cannot see the source.

  20. Max
    Max at |

    This is really not a good example. Generating HTML on the server assumes that your app(s) will display data without any understanding of it. 

    A much more flexible architecture would be to return the data as JSON and format it on the client.

    If your database is in the cloud, take a look at Espresso Logic, EmergentOne or Kumulos. There is no excuse for writing this code by hand when you can just leverage a service.

     

  21. admin
    admin at |

    @Max this is your opinion and I publish it! Depending on what you are doing there are no excuses for use third parties (with high prices) architectures instead of building your own one.

  22. Bianca
    Bianca at |

    Regarding the disadvantage of using script to retrieve data from DB, is it really bad? Will demanding the CPU Load to server be able to cause a server down? I am new to iOS development so I want to know the best way of doing this.

  23. Giovanni
    Giovanni at |

    Hi!

    thanks for your tutorial!! But … I have a problem!!

     

    I changed accountlist.php to get data I need, but when i Log my results I have something like:

     

    2014-06-15 01:28:26.467 ProvaPhp[12784:60b] Risultati: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

             "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;

     

    <html xmlns="http://www.w3.org/1999/xhtml"&gt;

        <head>

        <meta name="viewport" content="width=320; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>

        </head>

        <body>

            <table style="width:100%">

                        <thead>

                            <tr>

                                <td>Frase</td>

                             

                            </tr>

                        </thead>

                        <tbody><tr>

                            <td>

                            Frase uno, Prova!

                            </td>

                            <td>

                         

                         </tr><tr>

                            <td>

                            Frase due, Prova!

                            </td>

                            <td>

                         

                         </tr></tbody>

                    </table>    </body>

    </html>

     

  24. admin
    admin at |

    @Giovanni,

    I cannot understand, what is the error in your test?

    in strResult you should have the results from database in an HTML page, and…. you have this page, now you have to parse the results.

    Let me know if you are talking about a different problem.

  25. g
    g at |

    is it possible to use this aproach to insert data from app into remote db

  26. admin
    admin at |

    Yes, you can use this approach!

  27. g
    g at |

    So, do I have to compose your accountlist.php as NSString to include, say $sql = "INSERT INTO $table ('col1','col2') VALUES('val1','val2')"; statement instead of SELECT etc, save/upload it as .php file up on a server then fire up NSURLRequest on that php file? Something like that?

  28. admin
    admin at |

    You can create a new php file accepting a parameter like “account_name”

    let’s call it addaccount.php

    < ?php
        include(‘connection.php’);

        $table = “accounts”;

        // Build the sql query
        $sql = “INSERT …….. ” . $_GET["account_name"];

        $result = mysql_query($sql,$conn);

        if(!$result) {
            die(“Error retrieving scores ” . mysql_error());
        }
    ?>

    In the objc you have to change the line 

    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString@"http://www.yourdomain.ext/accountlist.php"]];

    in 

    NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString@"http://www.yourdomain.ext/addaccount.php?account_name=youraccountname"]];

     

    gg

  29. g
    g at |

    Great, thank you

  30. Men Men
    Men Men at |

    Thanks , I have just been searching for information about
    this topic for a while and yours is the greatest I have discovered so far.
    But, what about the bottom line? Are you sure concerning the source?

Please comment with your real name using good manners.

Leave a Reply


*

%d bloggers like this: