Wednesday, October 1, 2014

Learning PHP

PHP or Ruby on Rails? Which would be the easy server side language to pick up in no time? And how difficult to install it on Windows 8?

Well, these were the questions that I asked myself when I thought about a simple server side scripting language that I can use to explain some basics to a novice web developer.

I decided to go with PHP for the following reasons:

  • I read couple of chapters from a book (Head First PHP and MySQL) and went through couple of lessons in W3C Schools and felt it was easy.
  • I checked in dice.com and found more job opportunities for a PHP developer than a Ruby on Rails developers.
So....
  1. I followed this web site http://www.c-sharpcorner.com/UploadFile/47548d/how-to-install-wamp-server-on-windows-8-1/ and insalled WAMP (Windows, Apache, MySQL, PHP) server on my winodows 8.1 machine. Surprisingly, it was simple and straight forward. NOTE: Steps 1 through 8 were good enough for me and the WAMP server was up and running like an Arabian horse.
  2. From localhost index page, I opened the sqlbuddy and created a sample table in test database.
  3. I wrote the following simple program that talked to the database and provided me the response:

<?php // Connecting to a database using parameters... // mysqli_connect(hostname, username, password, database name) $dbc = mysqli_connect('localhost','root','','test') or die('Error connecting to MySQL server.'); // Select statement to get data from 'person' table $query = "select firstname, lastname from person"; // Executing the query $result = mysqli_query($dbc,$query) or die("Error querying database"); // Accessing the data that is obtained while($row = mysqli_fetch_array($result)) { echo $row['firstname'] . " " . $row['lastname']; echo "<br>"; } // Closing the database mysqli_close($dbc);
?>

So much for a day, huh? I am happy because I learnt something today!