Learning PHP


Now that I have my own domain and access to a server, I’ve been poking around with some cool open source apps. One of the first applications I installed was Wikka (formerly known as Wakka). Wikka is an Wiki written in PHP with some great features:

  • PHP and MYSQL make it lightweight and fast. (Okay so that’s propaganda from the website but it really is great.)
  • Page level security so you can determine which pages can be viewed and edited by others.
  • Like other Wikis it uses the CamelCase syntax for links to other pages but it also has some neat tricks for creating elements like lists, horizontal bars, etc.
  • Its functionality can be extended using plugins called actions. People have written actions to display rss feeds and calendars among others.

This last feature really got my creative juices flowing. As I examined the actions that others had written and p0ked around the actions folder in the Wikka installation, I saw that people were doing some pretty powerful things using pretty simple code. One project in particular to make Wikka into a Personal Information Manager really excited me as I wanted to use the Wiki as a my online dossier for ideas, programming projects, etc. Seeing different implementations of to-do-lists, calendars and schedules made me want to build my own.

My first step was to start learning PHP and MYSQL. Since I do a lot of work with SQL in my day job on Wall Street, I knew I would have no trouble writing the queries I would need for my event calendar. Being a semi-pro VB developer I thought PHP as a sister programming language would be pretty straightforward as well. I picked up J.W Gilmore’s Beginning PHP5 and MYSQL: From Novice to Professional. The book is great for beginners, easy to read especially if you are familiar with basic programming concepts but not so basic that you feel the author is treating you like a novice. After the first sixty pages and a few examples, I felt confident enough to poke around myself and I printed out some of the Wikka action code to see if I could pull it apart.

With the help of the book and some specific searches of the PHP.net website, I was able to write a simple date action which would allow me to enter “{{date}}” on a Wikka page and it would print out a formatted version of the current date. Emboldened by the simple success, I jumped way ahead of my skill set to the end of Gilmore’s book and peeked at the code for connecting mysql to PHP. Here I was bested by the most humble of creatures: the semicolon.

I began my quest to connect a simple Contacts table in MYSQL to a small routine which would print out the results of a dynamic query into Wikka via a “{{contacts}}” action. I found some simple code on the About.com website and modified it with the login details from my own server. However, everytime I would load the sample.php file I would get a blank page. Coming from the VB background, I’m used to having Excel or Access shout at me via a dialog box with a cryptic error message which I would have to decipher using the posts of others on VB programming bulleting boards. By contrast this silent refusal to execute my commands was at first puzzling but soon became frustrating. I thought at first my php code didn’t like the MYSQL user name and password that I had set up for my test database. So I changed the user password several times. Then, I commented out the whole program and just concentrated on getting the connection to the database to work and print out “Database connected.” Once I got that working, I slowly started uncommenting my program line by line until the point where I would get the blank screen again. By the end of about two hours I had unraveled about half of the code and gotten it to work. My wife called me away for dinner sensing that I need some fuel. Nurished, I return to the joust. However as I was reviewing one line of code, I noticed that I was missing a semicolon at the end of the line. After adding it in and checking the remaining commented code for missing semicolons, I took a huge step and uncommented all of the code. With baited breath, I clicked the refresh button on my browser and to my joy, the formatted output of my query appeared in its proper place on my wiki.

My advice to young programmers who may find this post among the annals of history: remember your semi-colons.


comments powered by Disqus

Date

Thursday, March 31, 2005

Estimated Reading Time

3 minutes

Categories

Previous Article

Next Article