I have an app that uses a few php scripts to access a mysql database. Can anyone advise on how to implement an offline version? I understand it is easy to create an SQLLite database in the app and populate it when the web server is available? true?
When I want to query it, is it possible to do that using the pre-existing php?
thanks in advance
HMJ
It's important that you make the distinction between the components you are speaking of - PHP is a server side language that is meant to carry out the DB queries. SQLite is the iOS framework that allows us client-side DB management on the iOS operating system. On the iPhone you can carry out the same queries that are generated using your PHP but they are to be built using objective-c. There are some useful wrappers that do this, including FMDB.
Kodiak PHP runs on an iPad. It has PDO installed. You can create a local sqlite database. I tested it with this code:
<?php
error_reporting(E_ALL);
$db = new PDO('sqlite:test.sql');
$n = $db->exec('DROP TABLE IF EXISTS USER');
$n = $db->exec('CREATE TABLE user (login TEXT)');
$n = $db->exec('INSERT INTO user VALUES("joe")');
$r = $db->query('SELECT * FROM user');
foreach ($r as $row) {
echo $row['login']."\n";
}
?>
In regard to PH7... it just implements the PHP language and a some functions, it does not support all PHP functions nor extensions. For instance, PCRE is often used for regular expression processing. PH7 does support it. PH7 is a rewrite, intended for embedded applications, basically a more capable scripting engine such as Lua, but not as big a footprint as Javascript.
Kodiak PHP is an actual PHP port. Use phpinfo(); to see what is has compiled into it, it's quite a bit.
To run your SQL scripts in an iOS app, you'll need to compile a PHP engine into your iOS app and get Apple to allow it :) - Kodiak is able to do it because Apple allows exporting files written in their app, but Apple does not allow importing files into the app. Therefore, you must use copy/paste. The app is intended for writing and testing code not running a bunch of PHP script to create an app.
In short, the answer to your question is: Yes, it is possible to run PHP and write to an sqlite database in an iOS app. However, to do so you'll need to compile a PHP library into your app. Compiling PHP for iOS is no small feat (I haven't done it yet). Kodiak has done it, but I have not found a freely available PHP library for iOS yet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With