Wednesday, November 24, 2010

Introducing server side softwares!

We will look at some cool softwares which we can use for a Apache, MySQL and PHP setup.

It is a real dread if you want to try to configure PHP, MySQL and Apache from scratch. The very first time when I try to install the 3 components separately on my MacBook, it took me an entire day. If you are considering to take up this challenge, do read the installations for each components carefully. Certain versions of one software can only work with certain versions of another software (especially the latest versions).

While working on my project, I realized that I have to reconfigure PHP so that it can support IMAP and IMAP-SSL. IMAP-SSL is required to access Gmail. I have already written the installation for mac in my first post.

I have tried to use XAMP (for all platforms), MAMP (Mac, Apache, MySQL and PHP) and even WAMP (Windows, Apache, MySQL and PHP) (On my Windows platform). However, the reconfiguring of the 3 softwares to support IMAP-SSL is difficult. Another key consideration is the difficulty in upgrading the individual components. Many websites which provides the solutions to installing the components, are seriously outdated. If you are looking for a client interface program to get some work done, you certainly can consider these 3 softwares.




One important software that you all should consider using is Netbeans. You can also use it to program with HTML, XML, Javascript, Java, C, C++, PHP and many others. I am currently using Netbeans to write my PHP programs.


If you are looking to design your MySQL, you should seriously consider MySQL WorkBench.
MySQL allows you to design the database using the Entity-Relationship Diagram (ERD). The most cool thing about the software is that it allows Reverse and Forward Engineering!!

This means that I can now design a database model, click on Forward Engineering and pesto! The database is built and ready to be used! The Reverse Engineering takes in your codes and put it into a ERD. One powerful component about MySQL WorkBench is that it allows you to connect directly to localhost and at the same time, provide a great graphical interface. This software also enhances server administration process and simplify the import and export of databases process.




Do drop in some comments if you have any other softwares to recommend! =)

Sunday, November 21, 2010

HTML, PHP and MySQL overview

PHP is a server-side scripting language. It is often used together with HTML to "pass" information to the server. MySQL is a Relational Database Management System (RDMS). In simpler terms, it is a database management system which is used to store data into tables. These tables are linked together by relationships (Hence it is called a Relational Database). 


Here is a basic application for a HTML form. The form data is saved into the database. Below shows the sequential flow for a simple data insert into the database.


As seen in the flowchart above, 
  1. After the user keys in the data on the HTML form, it will be sent to PHP. 
  2. PHP gathers the data and connects to MySQL (How it connects, we will discuss in further blog entries). 
  3. After the connection is done, PHP sends the data to MySQL. MySQL receives the data and stores it.

Another application is when a user wants to search for things inside a database. For example, you might want to search for the availability of a book in the library. Below shows how a user starts the search and how the results are displayed to the user.




  1. The User enters a search request in HTML. 
  2. PHP gathers data from HTML, connects and send the query to MySQL. Query is like a search request. For example, the results that you are interested to find, are books which are published in the year 2010 only. With so many books in the library's database, PHP must provide a query to MySQL so that it can return the correct information.
  3. Once MySQL receives the query from PHP, it will perform the search in its database. 
  4. After the search, it will return the results to PHP. 
  5. PHP will retrieve the results from MySQL and send it back to HTML. 
  6. HTML will now display the results for the user to see.


Hope you all enjoy my HTML, PHP and MySQL overview! Do subscribe to my blogspot! Do share with me if I make any mistakes. If you have any topics to discuss, do let me know so that I can post it up! =) 

Friday, November 19, 2010

Oracle Certified Associate, MySQL 5.0/5.1/5.5 certification (CMA)

I went to take an Oracle examination on 27th Oct 2010 and successfully obtained an Oracle Certified MySQL Associate (CMA).

Prior to the examination, I bought the guide book MySQL 5.0 Certification Study Guide from Amazon and read through all the chapters required.

Some important notes:
  1. Some websites recommended certain chapters or sections to study for the examination. Most of them did not include the Joining Table section.
  2. Also, do note that for Joining Tables, only INNER JOIN is tested (At least for my examination. There are 4 questions on INNER JOIN). 

Here are the exam contexts
Exam Contents - Certified MySQL Associate
  • Theory, Terminology and Concepts (10%)
    • Client/Server Concepts
    • Database and Database Objects
  • Data Definition using SQL (25%)
    • Databases
    • Data Types
    • Tables
    • Constraints and Indexes
    • Views
  • Basic Data Manipulation using SQL (25%)
    • Recurring SQL Constructs
    • Adding data
    • Modifying data
    • Removing data
    • Searching data
  • Advanced Data Manipulation using SQL (20%)
    • Expressions
    • Grouping and Aggregate Functions
    • Joining Tables
  • Transactions (10%)
    • Transaction Concepts
    • SQL for working with Transaction
  • Import/Export (10%)
    • Tools for Import/Export
    • SQL for Import/Export

One key tip for the examination is to practise the questions in the CD and do some practice questions which can be found online. Another tip is to try out the examples on an actual MySQL to understand the topics even better. 

If you want to take a quick look at some of the MySQL syntax, you can check out my other blog here.


You can check out the price of the exam at the Oracle homepage 


I did relatively well for the examination, scoring 92% which means getting 46 out of 50 questions correct. You will know your score immediately after you ended the examination. 

If you have any questions on MySQL, do send me an email so that we can discuss about it. Alternatively, you can post it here so that we can share and discuss! :)

Thursday, November 18, 2010

First time programming?

My first programming language is C. During my first year in university, I cannot understand a thing about programming. Yes, I know what are functions, datatypes, etc. But whenever I am asked to write a program, I just cant write a thing. The one thing I do not know is: HOW TO USE WHAT I HAVE LEARNT TO MAKE A PROGRAM!?

The stuff which are taught in lectures are just the basic tools for a program. One good analogy is: In order for you to build your house (program), you use a hammer to hammer the nails onto the wall, a spanner to fix the pipes, etc. In order to PROGRAM (build your house), you need to know how to use all these basic tools such as functions, datatypes (int, char ).

The best way to do a program is to really use the divide and conquer method. Firstly, you look at a house and plan out what are the components that you need.

Next, build one component at a time and test the component THOROUGHLY to make sure it is fully workable and returns the result that you want!

For example, a toilet bowl's function is to be able to flush away all the dirty stuff when we press the handle. We will not wish to have the dirty stuff spray onto us when we press the handle. Thus, it is very important to test the component to make sure the functionality and result is what you really want.

Normally, I will put in outputs (in C: printf, C++: cout, PHP: echo) which can show the values of the variables that we use. In some cases, the values in the variables may not be what we expect it to be.
For example:
function testcompare(){
    int i = 5;
    int j = 6;
    if (i == j)  // We want to compare instead of assigning j to i.
   {
       cout >> "true";
   }
   else
  {
       cout >> "false";
  }
}

We want to test if i is equal to j, we will perform these actions. However, in most programming languages,  '=' is an assignment and not a 'is equal to'. Thus, it should be '==' instead of '='.

For beginners, on first look, we may think that this function will function in what we want it to be. However, it does not.

If we output the value of i and j within the if, we can detect that our comparison is faulty as both i and j will give the value 6.

Mac Commands, ./configure

What is ./configure!?
I first saw this when I was configuring my PHP and it took me some googling to understand what ‘ ./ ‘ and ‘configure’ means.

Here is the answer.
In terminal, When you are at a specific folder named /usr/, ‘ ./ ‘  just means inside this specific folder and ‘configure’ is the Unix Executable File name.

In summary, it means that there must be an Unix Executable File called configure in the folder /usr/.

Mac Directory: /usr/

As a new Mac user, I was never exposed to Linux or Unix style commands. There is this particular thing that really frustrates me whenever I try to google for instructions on how to perform certain actions on my mac.
This is it: /usr/

I spend a long time trying to find this directory but I cant even find the /usr/ folder!! So where and what is it?! Is this some form of shortform?!
After some intensive googling, I found out that /usr/ is a folder which is “hidden” in the new Mac systems. In order to view it, either we use the terminal to view the file or activate the “Show All Files in Finder” so that all the hidden files can be seen.

All you have to do is to open your terminal and paste this codes:
defaults write com.apple.Finder AppleShowAllFiles YES
It is that simple.. =)

PHP 5.3.2, MySQL 5.1.49, Apache 2.2.16 on MAC OS X 10.6.4

I need to compile PHP, MySQL and Apache on my Macbook Pro. It is really not easy! Besides trying to follow the numerous out-dated posts in the entire internet, I have to contend with a lot of technical and software issues with regards to my MAC (I am a new Mac user).
The versions in which I used are
PHP 5.3.2
MySQL 5.1.49
Apache 2.2.16
on Mac OS X 10.6.4
There are some websites which I have referred to and I will definitely recommend you to read.
  1. Sean Coates’ Blog – I figure out how to download PHP and Apache using the terminal PLUS the installation of libiconv-1.13.1. The file iconv caused such a great headache when I tried to compile things using MAMP. He also solved another headache by teaching how to download libpng, libjpg, libxml2, … All these took me several days to solve.
  2. Zero Inverse’s Blog – I require IMAP-SSL so that I am able to use Gmail from my PHP. Initially, I am using MAMP. But MAMP does not support IMAP-SSL. (It supports IMAP and OpenSSL but you need to recompile the Apache to enable IMAP-SSL support).
Here are my installation steps:
  • Download and install Xcode. You need Xcode to enable the Make command (and many other developer tools).
  • Install Homebrew. I am not using Macports.
  1. $ curl http://gist.github.com/raw/323731/572b315c4f7ee78244de70e7ad703c8ae324da7a/install_homebrew.rb > install_homebrew.rb
  2. $ ruby install_homebrew.rb
  • Install your own iconv. Although Apple does provide, I faced a lot of problems when I tried to use it.
  1. $ curl http://ftp.gnu.org/pub/gnu/libiconv/libiconv-1.13.1.tar.gz | tar -zx -
  2. $ cd libiconv-1.13.1
  3. $ ./configure –prefix=/opt && make && make install
  4. $ cd ..
  • Download and install Apache-HTTPD
  1. $ curl http://apache.mirror.iweb.ca/httpd/httpd-2.2.16.tar.bz2 | tar -jxf -
  2. $ cd httpd-2.2.16/
  3. $ ./configure –enable-rewrite –enable-ssl && make && make install
  4. $ cd ..
  • Install PHP dependencies using Homebrew
  1. $ echo “gd jpeg libpng libxml2 libzzip mcrypt mysql” | xargs brew install
  2. $ echo “libpng libxml2 readline” | xargs brew link
  • Install PHP from source. A patch is required else the iconv won’t work.
  1. $ curl -L http://ca2.php.net/get/php-5.3.2.tar.bz2/from/this/mirror | tar -jxf -
  2. $ cd php-5.3.2
  3. $ curl http://www.php.net/~scoates/patches/php-5.3.1-Makefile.global-iconv.patch | patch -p0
  4. $ ./configure –prefix=/usr/local –with-xsl –with-gd –with-zlib-dir –enable-sockets –enable-exif –with-mcrypt –enable-soap –enable-embedded-mysqli –with-mysqli=mysqlnd –with-mysql –with-pdo-mysql –with-curl –with-libedit –with-apxs2=/usr/local/apache2/bin/apxs –enable-mbstring –with-openssl –with-imap –with-imap-ssl –with-iconv=/opt && make && make install
  5. $ cd ..
  • Configure Apache
  1. Make sure that the module is loaded. It should be loaded by default.
    LoadModule php5_module modules/libphp5.so
  2. In /usr/local/apache2/conf/httpd.conf, add these:
    If you are using terminal, type this: cd /usr/local/apache2/conf/ [enter] and pico httpd.conf [enter]. Under LoadModule php5_module modules/libphp5.so
    AddType application/x-httpd-php .php
    AddType application/x-httpd-php-source .phps DirectoryIndex index.html index.php
  3. Before checking phpinfo, it is a must to check whether there are any other applications using the default port 80. My port 80 was occupied by the built in apache and cannot be accessed. I solved it by switching to port 8888. Here are the 2 lines which I edited in my HTTPD.conf file.
    Listen 8888 and ServerName localhost:8888
  4. Now test Apache + PHP by creating php.info().        $ echo “<?php phpinfo(); ?>” > /usr/local/apache/htdocs/index.php
    $ ln -s /usr/local/apache2/bin/apachectl /usr/local/bin/apachectl
    $ sudo /usr/local/bin/apachectl restart
  5. Now visit localhost:8888/index.php. You should see this:

Most importantly, I saw this…

Hooray! My IMAP-SSL is up!!