Welcome to the first PHP Singapore User Group meet up for 2008! Today, the meeting is held at Singapore Management University (SMU) at Seminar Room 2.1. So if you are around the area, do pop by and let the security know that you are attending the PHP. Besides free good food and drinks, you get to surf the Net for free if you are not on any paid broadband or if your Wireless@SG is not working as usual.

The highlights for today includes Design Patterns in Web Applications and PHP201 – connecting to MySQL Database. This meet up is different from the previous one in that the tracks are ran consecutively instead of being concurrent like the previous one. In this way, we would be able to provide you with the entire content via live blogging.

The first track will be presented by Tang Chin Yong, who is a code crew from Ablewise Free Classifieds while the second track is covered by Michael Cheng. For those who are present at the meet up, do sit back and relax and mingle around.

7:52pm: We have reached the limit for simultaneous log-on and are trying to resolve this ASAP. Meanwhile, do… enjoy the food. =)

7:55pm: The room’s filling up to almost 3/4 of the seminar room. It’s beginning to look like a really big up for this month’s meet up. Indeed, what a great start to the new year! =) We have the familiar faces in the room today, including Ming and Nannywen from Nuffnang, Damien, Lester, Bernard Leong, Yuhui, Nicole, Neil and the list goes on.

8:00pm: Here’s the official word. The number of Internet connections had been max’d out. So for those who have wireless connection now, the official word is to continue enjoying it. For those who do not have Internet connection, well, we hope to iron this out by the next meeting. Michael sends his apologies to everyone else who are not able to connect.

8:05pm: Michael started off with an opening address introducing himself and the Singapore PHP User Group in Singapore. He is also covering the mission of the PHP user group as well as the vision for this year. For the first quarter of 2008, we would also be doing a facebook developer garage for those who enjoy doing facebook stuffs as well as a PHP boot camp in June this year. A PHP apps contest is also in the pipeline to bring in the fun and thrill.

If you would like to help out with the PHP user group, do feel free to contact Michael because he feels that there are much more that we can achieve together. We have some new members including Damien, Neil, Terrance, Shawn, myself (!), Bernard (marketing, and working with Neil), Adrian Quek (curriculum together with Chin Yong). For more information, you may drop by the PHP Wiki or facebook.

8:15pm: Chin Yong has taken over and is starting on the first official professional track. He is a little nervous now because he feels that he can never be prepared sufficiently for such stuffs. This section will be covered by himself and Tji Han.

In a nutshell, they run Ablewise.com and have been through various stages and would like to share their experience. Today, they will cover design patterns by giving an introduction as well as highlighting 3 common design patterns. There is also a hidden agenda which is to determine possibility of more design patterns and a … ahem, shameless plug to get publicity.

The overview of today includes covering design patterns, what design patterns are not, the gang of 4 format and various selected design patterns. For those who are not familiar with design patterns, they are actually using 1 type too. It’s know as spaghetti pattern. =S

What are design patterns?

Theoretically, there are more than 1 type of design patterns, but there is usually 1 preferred over the others. Design pattern is platform independent, which is pretty much like object orientation, which is essentially a concept.

There are no hard and fast rules in coding and design pattern is not a hammer for all nails. There are no hard and fast rules and it’s highly contextual. However, different design patterns are not applicable to all languages. and it does not make any language better.

He’s covering the gang of 4 format, which is created by 4 founders.

The purpose of this pattern is that it should tackle the problem at hand. It’s not easy to mention in words now, so it’s better to wiki it here.

This track is a little too technical with about 40% of the people in the room looking a little lost. Frankly, I am a little lost too. So I’d get the slides from him later to be uploaded either here or on PHP Wiki. =P However, if you are really new to design patterns, one take hope lesson is that you should code to implementation and not to interface.

Chin Yong is going through the Facade Pattern now, which is one of the simplest design pattern available. A question is now posed to the floor which someone probably gave a different answer from what he was expecting. So the politically correct answer is to admit that it depends on the scenario.

Tji Han is now on the floor, covering MVC Patterns. He feels that it is possible to have an entire page on a single PHP page, which is probably not conducive for programmers and designers to work on. Hence the View and Model layers are separated and controlled by a main controller so that each of the people working on it need not share the page.

Depending on what kind of framework you are using, with Cake PHP framework being preferred for ablewise.com, He is currently running through some sample code on the screen which shows how a programmer does all the coding for the backend while designer does a simple call through another file.

For people who are new to design patterns, they may wish to pick up some books from the NLB which includes (1) PHP 5 objects, patterns and practice, (2) design patterns and (3) design patterns for dummies.

Lastly, they would like to thank Wikipedia and Michael for making this presentation possible.

The parting shot for this presentation:

  • PHP Cheat Sheet
    • ilovejackdaniels.com

One of the attendees asked about persistence in Cake PHP and the answer is that Cake PHP does cache everything when it is loaded so that they load much faster the next time these objects are called.

Michael suddenly realised that he forgot to ask the audience on their user type so that there can be more interaction during the break so that the entrepreneurs know where the seasoned programmers are and where the beginners are so that they can be left out guided.

Bernard Leong highlighted that in Computational Biology, they use design patterns in a way that they do not have to do the same thing over and over again. To this, Chin Yong highlighted that design patterns are meant to help the programmer achieve in a particular goal through appropriate use of the correct design pattern. Of course, the other advantage of having a well-thought programming methodology or design patterns is that code can be easily reusable.

Michael also highlighted that design patterns are really everywhere and that using frameworks makes things easy by providing a particular methodology for the programmer to follow. One member of the audience highlighted that there are literally 1000s of frameworks available and asked what should be looked out for while looking for a framework.

The answer to this is that people should use google as a tool (like typing "framework php") and taking what returns most. One important factor is to make use of a framework that is well-supported or well-used because at the end of the day, programmers will depend on the community to help them along with it. Of course, feature sets are also important, but it is something that will continue to grow as long as there is a community.

Another thing to look out for is the footprint – in that Chin Yong feels that a small footprint is important. To this, Bernard feels that refactoring is something that is also important. Michael summed this up by noting that there is really no 1 good solution to this, and that what’s important is that the goals of the project should be met, which includes phone support, community support (leading, bleeding edge technology?), and programmer preference (lots of code vs. little code, drag drop) amongst others.

Michael exclusively uses Cake PHP because it follows a lot of philosophical stuffs in that it is very similar to Ruby on rails – including convention (Cake PHP?) vs. configuration (not good in ROR, good in Symfony.com/.org). There are also various characters in different frameworks, although Michael strong advocates Cake PHP.

Shawn from the floor utilizes spaghetti framework because he feels that as long as it helps unify his programmers, it’d do. Nuffnang also started with the spaghetti framework because he started small, but has now started using the MVC framework because it got much bigger now. Another site that started with spaghetti includes facebook too.

8:55pm: There is now a break cum networking session and Ming from Nuffnang is here to do a show case on his product. The session will resume in about 10 to 15 minutes’ time.

9:20pm: Welcome back! We have Michael Cheng on the floor now and he’s presenting PHP201 PHP and MySQL. There will be 3 parts today where he will cover some database concepts and tubes and some active participation in coding from the audience. He is trying to describe what a relational database is, but because of the lack of images, everyone has to imagine how a relational database looks like.

To access data from a database, we have to know what the server address is, the port number, some form of user authentication and the name of the database.

Next up is the tubes. As one Senator said, the Internet is made up of tubes. The joke is that, the Internet is made up of tubes and when they get congested, we need tiers….


So what are the tubes? They are:

  • Mysql_Connect
    • server address, port number, user name, password comes here
    • it opens connection to database server
    • mysql_connect("localhost", "root", "root")
  • Mysql_select_db
    • mysql_select_db("database_name")
    • selects database to query
  • Mysql_query
    • $local_var = mysql_query("statement")
    • to retrieve data / initiates a database query
    • while ($row = mysql_fetch_assoc($local_var)) { do something to $row or $row[‘column_name’] };
  • Mysql_fetch_assoc
    • retrieves fetched rows
  • Mysql_close
    • Mysql_close()
    • closes the database connection
    • According to Michael, we should always close the connection while according to some books, MySQL does its own garbage collection
    • If this statement is executed twice or more times, it will report an error – hence to prevent the second one from reporting an error, we may use @Mysql_close()

Since the connect and select_db commands may be repetitive, we may use include or require to include an external file which contains all these commands. An example is include("config.php") or require("config.php"). The difference between include and require is that requires will return an error if a particular file is not found while include does not.

require_once is good if there may be a risk of nested includes that includes the same file more than once. For more information, some source code will be made available online. Members of the PHP Singapore User Group team will be there to answer your questions, if any.

9:43pm: We now come to the end of the PHP session. For more information, you may also refer to the official php.net official site. Today’s session is more precise because the core team felt that they may be going a little too fast or too much in the past 2 sessions. If you have any feedback, do feel free to leave some comments after this post.

Michael may be contacted at michaelchengchimun@hotmail.com, miccheng@php.com.sg and the official Singapore PHP User Group site is at www.php.com.sg

See you next month at the next PHP meet-up! Thank you!

Reader's Comments

Leave a Comment

%d bloggers like this: