This week I mainly focused on trying to learn how a PhoneGap application can utilize PHP to post information to a database and also get information from that database. Additionally, I tested a couple of bend sensors with John that he had created but neither of the sensors worked.
PhoneGap and PHP Example
I browsed the Internet for an example app that demonstrated how to use PhoneGap and PHP together and found a couple of tutorials for how to set up such an app. The simplest and most in-depth walk-through that I could find was an example for a “Bug App” that allowed you to retrieve a list of bugs that had been added to a database and also add new bugs to the database. I found the walk-through here.
I began following the tutorial by creating a local MySQL database called bapp and a table inside of the database called bugs with properties id, title, details, priority, and date_time_added. Setting up this MySQL database was not a problem at all.
I then continued through the tutorial and followed the instructions for creating the bugs.php file which got all of the records for bugs that had been stored in the database and displayed the bugs’ id and title in an array. The page loaded fine when I tested it in the browser, but there were no bugs in the database yet so it simply loaded an empty array.
I then went into PhoneGap and created a new application and linked the index.html page to files called Zepto.js and also cordova-2.0.0.js that I had downloaded and placed in the proper folder. Additionally, I copied the HTML code for the index file directly from the repository for the app that was provided on the walkthrough.
I then proceeded to change the urls in the index.js file so that the app should get the list of bugs through my bugs.php file and posting its information through a file that I had copied from the example called add-bug.php. After creating the add-bug.php file I tried to test it in the browser, but continued to get a syntax error that read: “Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘)’ at line 1”. I looked over the tutorial’s instructions, the SQL syntax in the PHP file, and how I created my database and table in MySQL many times but I still didn’t know why I was getting that error message. I didn’t feel like I was getting much information out of that error message and so I spent quite a bit of time trying to figure out what I was doing wrong. I eventually figured out that the reason I was getting an error was because my variable $bugPriority wasn’t yet given a value and so it turned out there wasn’t really a problem with my add-bug.php file.
I followed the instructions for the rest of the tutorial and felt that I had done everything exactly how I was told to and that my app should work, but I still had issues with the app. For example, the app’s form to add a bug which was supposed to open when a button was pressed wouldn’t open when I tested it in the browser using a click event and also wouldn’t work on my phone using a tap event as it had said to do in the walk-through. I believed many of my problems were likely related to how my server was set up. I was luckily able to meet with Katie after the ProHealth meeting on Friday and together we essentially started the tutorial again from the beginning by setting up GitHub Desktop on my laptop and downloading the entire repository for the example app in the walk-through. Katie also helped me work through a couple of my server questions and issues and told me that I’d need to set up the directory that I was working in to be the local server.
Over the weekend I worked on fixing my server and also working through the PhoneGap code and attempting to figure out how everything was supposed to work. I’m still having problems switching between app pages and the example app that I’ve been attempting to create does not yet work, but I feel that I’ve made some progress and I’m much closer now to a working PhoneGap app than I was before.
Any and all updates for my progress on the app can be found here in my Github repository.