Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
0

Video2Brain question for David Powers

Enthusiast ,
Oct 22, 2012 Oct 22, 2012

Copy link to clipboard

Copied

Hi David (and anybody else wanting to read this), I have a number of projects where I am being asked to create mobile apps with HTML5 packaged through phone gap, but I am also being asked to include a CMS for ease of editing. I can create the CMS no problem, and I can create the the mobile app too, but I have no idea of how to marry a native app with a remote database so the app's contents stays up-to-date. I mainly need to pull data, but also insert data on occassions. If I can get the pulling of data to work, that will help me immensely.

My question to you David is: Do any of your Video2Brain courses cover this kind of subject?

If anybody else knows of any tutorials on the net, or in books that cover this subject, I'd love to hear about them.

I am assuming it's not important, but just in case it is, I am using DWCS6, MySQL and PHP

Thanks.

Mat

TOPICS
Server side applications

Views

1.1K
Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 22, 2012 Oct 22, 2012

Copy link to clipboard

Copied

By the way David, I would've asked this question to you personally by email through your own website, but you have cleverly hidden your contact details... so, sorry for personalising this post to you on a public forum!

Mat

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 23, 2012 Oct 23, 2012

Copy link to clipboard

Copied

PhoneGap creates native apps using HTML, CSS, and JavaScript. It does not support PHP or any other server-side technology.

If you want to communicate with a remote database, you need to use JavaScript to send an Ajax request to the database, which needs to send the response formatted as XML or, preferably, JSON. You then use the success callback function of your Ajax request to display the results. It's also possible to store data on the mobile device using the Web SQL API, which uses JavaScript rather than PHP to communicate with the database.

My video2brain courses don't go into this level of detail. My book, Adobe Dreamweaver CS5.5 Studio Techniques: Designing and Developing for Mobile with jQuery, HTML5, a..., has a fully worked example of creating a local database on the mobile device using Web SQL, but it doesn't cover accessing a remote database.

There's an online tutorial by Raymond Camden about synchronizing remote and local databases with a PhoneGap project at http://css.dzone.com/articles/adding-database.

There's also a very detailed article in the Adobe Developer Connection by Andrew Trice about connecting a PhoneGap app to a database in the cloud at Database.com: http://www.adobe.com/devnet/phonegap/articles/phonegap-apps-powered-by-developercom.html.

I haven't tested the code in either article, but both authors are very reliable.

If you don't have any experience of using Ajax, I recommend using jQuery. It makes Ajax communication very simple. On the PHP side, use json_decode() and json_encode() to handle the incoming and outgoing data.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 25, 2012 Oct 25, 2012

Copy link to clipboard

Copied

Thanks for your reply David.

So, I assume that I can take a remote php page with the required recordsets, print an xml file from that, and then draw data from that 'printed on the fly' xml file into an html file, or even direct into the app. Is that right?

Mat

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 25, 2012 Oct 25, 2012

Copy link to clipboard

Copied

When transferring data to and from mobile applications, it's better to use JSON, which is more compact than XML. It's also a lot easier for the app to consume the server response as JSON because the data is formatted as JavaScript objects.

On the server side, you need to decode any JSON received from the app, and use it to query the database. The database result then needs to be converted to JSON using json_encode(), and output using echo.

The Ajax callback function inside the app waits for the response, and then processes it.

Handling the request on the PHP side is simple: the request comes in, you query the database, and output the result as JSON. Dealing with the response inside the app is far more complex because it all needs to be done with JavaScript.

I haven't yet tried it myself. It's something that I want to do, but haven't yet found the time to experiment.

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Oct 25, 2012 Oct 25, 2012

Copy link to clipboard

Copied

LATEST

OK, thanks David... makes some sense to me, although JSON isn't something I've tried before.

Well, I know you've published a few books in your time, but all I can say is that if you created a book on this subject alone, it would sell! The amount of forums I have trawled where people are asking for exactly what I am looking for implies that many are crying out for some guidance on this subject!

This subject is a very closed book -- it's very reminiscent of the early days of database driven websites where there is very little info about and it's as though the elite want to keep it elite... which is understnadable!

Votes

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines