0

I'm not quite sure I know how to ask this question properly.. but here goes nothin. I'm using PHP files to query data from a MYSQL database. In Xcode, I use NSJSONSerialization and grab the info. The PHP files need to be on the host's computer where the database is.

Question: Is there any way to put the PHP files in the iOS Project's directory so I don't have to manually put the PHP files on every host computer's database location that I connect with?

Below is just an example from my PHP file that I use to connect to MYSQL, query and such.

$mysqli = new mysqli("localhost", "root", $_REQUEST['password'], $_REQUEST['db']);

$moneyFormat = "0.00";
$moneyChar = "$";

if ($mysqli->connect_errno) {
echo "Failed to connect to DB.";
die();
} else {
if ($_REQUEST['type'] == "basic") {
    $includeTaxes = false;
    $netSales = 0;
    $voidSales = 0;
    $discountSales = 0;
    $guestCount = 0;
    $loggedIn = 0;

    $res = $mysqli->query("SELECT MoneyEXCH, include_taxes FROM it_tcompany");
    $res->data_seek(0);
    $row = $res->fetch_assoc();
    if ($row['include_taxes'] == "0") { $includeTaxes = false; } else { $includeTaxes = true; }
    $moneyExch = $row['MoneyEXCH'];
Machina
  • 232
  • 1
  • 12
  • In short, PHP files require a SERVER(example:- APACHE) to run. As there is no server in iOS application, the PHP files will be treated as normal HTML files. So you have to put your PHP files to your host's computer where the database is. – Yogesh Suthar Jul 04 '14 at 03:36
  • Okay I understand that. Is it possible to direct connect to MYSQL database from iPhone, so I don't need the PHP files? Thanks – Machina Jul 04 '14 at 03:38
  • 1
    No, that is also not possible, you will require `PHP, ROR, JAVA, etc` to connect to MySql server. – Yogesh Suthar Jul 04 '14 at 03:43
  • Yes if you can execute PHP in your app with PHP Server installed in your app, that certainly possible in Jailbroken device with cydia, not in your case. Though I guess you want to use php for database? You can easily convert your mysql database to sqlite database, and use directly in iOS, see here for how convert http://stackoverflow.com/questions/3890518/convert-mysql-to-sqlite – iphonic Jul 04 '14 at 06:34

2 Answers2

3

Well, the right answer for your question would be no. But I think you are misunderstanding some concepts with web servers. Is not ideal to have every user to run its own database (sorry if I misunderstood you). The database and web server will be running somewhere else. And the proper way is for you to have only one location (technically two, one for development and the other one for production)

1

I agree with others that this does not seem like the right design decision.

That said, there are services that will allow you to get information out of a database without any php directly from iOS. If for some strange reason you must have a separate database for each one of your users you can perhaps use one of these services. Amazon for example has an SDK for it's AWS service and it provides you with several cloud storage options. Same is true for Google Cloud.

Mika
  • 5,497
  • 5
  • 33
  • 77
  • Great, thank you! Yeah I'm building an application for a POS System Company, in which each store owner has a database for their (multiple) stores. – Machina Jul 04 '14 at 14:25
  • 1
    Yea figured it was something like that. You should check to see if the POS company uploads the data to the cloud and provides an sdk to access it. – Mika Jul 04 '14 at 18:24