rite once, run anywhere. This Java motto seems to hold true even for mobile devices. Indeed, since it was born J2ME has had an ever-increasing impact on mobile development. Some may argue that J2ME is not as portable as other Java technologies, but even so, the result obtained on different mobile devices is, in most cases, still acceptable.
When thinking of a client/server application with a J2ME client, the first choice that comes to mind for the server-side implementation is J2EE. Of course, if you have a Web Server that supports J2EE then your choice is undoubtedly a good one. But what if you don't have such an expensive Web server; instead, you have a low-cost domain that supports only PHP? In this case you have two options:
- Spend more money to obtain J2EE support.
- Write your server-side application using PHP.
This article discusses the second option of course, but there's still something missing: What if you want to store any information transmitted by the client for later retrieval? You'll need some type of persistent storage, and for most large applications, you'll probably want to use a database rather than simple file or XML storage. I've selected MySQL for this article for the same reason I chose PHPit's inexpensive. Figure 1
shows the complete interaction between the client (J2ME), the server (PHP), and the database (MySQL).
shows the simple database schema used for the sample project. The downloadable code
for this article contains a script you can use to setting up the database with MySQL.
|Figure 1. Client/Server/DB Communication: Here's a tTypical scenario involving a Client/Server application using that uses a database as a for persistence medium.||
|Figure 2. DB Schema: The figure shows the The simple database schema used to store the blog information.||
To run the samples for this article you'll need the following software:
|Author's Note: If you're running Windows and haven't already installed PHP, MySQL and Apache HTTP Server, you can use EasyPHP to install the aforementioned software in "one single shot." EasyPHP also installs PHPMyAdmin which is a simple administrative application for MySQL.