MySQL from PHP to Xcode?

I would like to clear my doubts about connecting a MySQL database using Xcode. My application will need to extract data from MySQL since there will be a login screen. So, in order for me to be able to get data from my database, do I need to create a database using MySQL and connect it using PHP, and then connect PHP to Xcode?

I am developing applications, but I am entrusted with the task of doing this for my school.

I would need a lot of help creating PHP to connect MySQL (it would be nice if its step by step instructions). I really really appreciate your kind generous answer.

Thank you in advance!

+4
source share
4 answers

It is very easy to connect to a MySQL database with PHP. There are several APIs for this, mysql and mysqli. Mysqli is probably better used, but slightly denser. Mysql works as follows:

$db = mysql_connect("host:port", "username", "paswword"); mysql_select_db("my_db", $db); # say we want to select everything from the table Persons $result = mysql_query("SELECT * FROM Persons"); while ($row = mysql_fetch_array($result)) { # do your magic # columns are accessed in a zero based array # such as $row[0], $row[1], etc. # look at mysql_fetch_assoc to see how to access # using the column names } mysql_close($db); 

Here's an older but still valid W3c tutorial here and MySQL PHP API Reference . For API differences, read the MySQL PHP Driver Overview .

As mentioned in other answers, you will want PHP to output something like JSON or XML to communicate with your application and Xcode.

+3
source

This tutorial steps you through the entire process, from creating a web service to implementing a web service in your application. I found it very easy to follow.

Part 1: http://www.raywenderlich.com/2941/how-to-write-a-simple-phpmysql-web-service-for-an-ios-app

Part 2: http://www.raywenderlich.com/2965/how-to-write-an-ios-app-that-uses-a-web-service

+2
source

It looks like you need some kind of WebService. You can simply create your PHP pages and allow them to output a given format (e.g. JSON or XML). Then, in your Obj-C application, just do web queries and parse the results.

There may be some existing solutions that you can use, Webservice is the keyword here.

+1
source

Here it is best to connect to mysql database, it is best to use JSON/SOAP/XML/PHP websevices to talk between your database and your application.

Connecting directly to the device with the reason database is a bad idea, you have to enable global external access for it to work. You can keep your data more secure if scripts are running on your server on the server.

One example of how to do this is to create PHP pages that export XML data as an export of mysql data, and use GET POST methods to publish data to PHP pages for writing to your database.

0
source

Source: https://habr.com/ru/post/1391602/


All Articles