Archive for July, 2006

PHP Video – configuring WAMP

Sunday, July 23rd, 2006

Yet another WAMP video tutorial. This one continues the installation process and shows you the WAMP control panel.

WAMP control panel video tutorial

Questions, comments?

Thanks,

Stefan

PHP Video – installing WAMP

Sunday, July 23rd, 2006

I’ve released a new video on installing WAMP on a PC.

WAMP install video tutorial

Any comments?

Thanks,

Stefan Mischook

PHP Video Variables Part 1

Sunday, July 23rd, 2006

I’ve released a new video on PHP variables.

PHP variables

Should you have any questions or comments, please feel free to ask here.

Thanks,

Stefan Mischook

PHP Design Patterns – when should they be used?

Saturday, July 22nd, 2006

Since the release of PHP 5, the PHP world has slowly started to get into more advanced programming, things like object oriented concepts and the use of design patterns.

WHAT ARE DESIGN PATTERNS?

In a nutshell: design patterns are standardized ways (with each having their very own name,) of solving common programming task/problems.

Over the years, programmers have identified reoccurring problems and have come up with ways to deal with those problems – by giving the programmatic-answers to those problems, a nifty name.

Common Design Patterns by name:

  • Factory Pattern
  • Singleton Pattern
  • Observer Pattern
  • Decorator Pattern
  • etc …

The idea is to:

  1. Create a lingo that programmers can use to more efficiently speak to each other – ‘use design pattern xyz’.
  2. Provide a blueprint (if you will) of techniques/patterns programmers can refer to when writing code.

… in the end, it supposed to make programming easier and result in better and more consistent code.

WHEN SHOULD YOU START LEARNING AND USING DESIGN PATTERNS?

You should probably start looking into design patterns as soon as you have a handle on object oriented PHP. That said, I personally believe they start to play a valuable role in practical work, only when the PHP projects are of a reasonable size.

… there is no point in introducing the added complexity of design patterns into a simple PHP project – that’s a mistake the Java community is still trying to recover from.

THE DARK SIDE OF DESIGN PATTERNS

The problem with many common design patterns is that they add unnecessary overhead.

Many patterns assume that you are working in the enterprise arena (very big projects,) where the software will be expanding and changing over time – most (99%) PHP projects are simply not that big.

As such, the extra complexity (people have to understand the design patterns) and the extra code it usually takes to execute most patterns, makes using many design patterns a bad idea.

WHAT CAN WE LEARN FROM JAVA’S BAD EXPERIENCE?

The Java communities overly anal need to follow theoretical constructs proposed by eggheads, who apparently didn’t actually write real-world software, resulted in the sacrifice of a once usable language: Java.

Java went down the dark path of over engineering, to the point where the Java community began to revolt – it got way too complex to do anything. So now we see the rise of Ruby.

Back to patterns …

People in the Java community started coming out with all kinds of new patterns – many books were published and with each new design patterns book, Java become more and more bloated.

Some people will argue that the new design patterns were actually a symptom of the overly complex Java API. That may be true to a certain extent, but I still believe that the introduction of new design patterns contributed to the Java bloat.

CONCLUSION

I am not saying that design patterns are bad, I just think they should be used only in the right context:

you don’t need an 18 wheeler truck to move a chair…

Stefan Mischook

Book Review: Spring Into PHP 5

Wednesday, July 19th, 2006

Not a bad book for people who have a little PHP knowledge … but if you are a total programming novice, you will need to get another book … or better yet, my php videos for novices! I don’t usually plug my own stuff … but what the heck.

The thing that stands out for me, is the way the author is able to cover various PHP topics in a concise manner. He has also chosen topics that I think would interest most PHP programmers – they are practical.

Some highlights:

  • The section on string manipulation is very good.
  • Great coverage on the powerful sprintf function – something you don’t see often.
  • HTML form processing (chapter 5) shines.

My only complaint:

… though the book says that all you need to know is HTML, this is clearly not the case. Most web designers will have problems if they try to tackle this book from scratch.

Final comment:

If you have a little PHP background, this is a good book to get. I’m happy to have it on my nerd-book shelves.

The Top 3 Reasons to Learn PHP?

Monday, July 10th, 2006

With so many web programming languages (frameworks) out there today, it’s hard to settle on which one to use … even for experienced programmers.

Here is just a sample of the choices you have:

  1. PHP
  2. JSP/Servlets
  3. Ruby on Rails
  4. PERL
  5. Classic ASP
  6. ASP.net
  7. ColdFusion
  8. Web Objects

Instead of trying to fill up space with clever nerd-drivel, I am going to get to the point.

Here are the top 3 reasons to go with PHP:

  1. PHP is ubiquitous (that means everywhere).
  2. PHP is powerful.
  3. PHP is free.

Nothing is perfect (and that includes PHP,) but I think that the above three things make PHP the best web programming language out there today.

WHAT ARE DATABASES?

Thursday, July 6th, 2006

Databases are programs that are built to store and manage information. You can think of a database as a virtual filing cabinet … with extra bells and whistles.

Types of databases:

There are several types of databases used today. The most common being:

1. Relational databases.
2. Object databases.
3. Flat file databases.

You can think of each type of database as a different way (conceptual and practical) to store and manage information.

Each type of database has its advantages and disadvantages. That said, by far, the most popular database type is the ‘relational database’. That’s why we concentrate on them here.

WHAT ARE ‘RELATIONAL’ DATABASES?

As I hinted at above, each database type has a different concept on how data/information should be stored and organized.

A relational database stores (and organizes) its data/information by creating relationships between different pieces of information (stored in virtual containers) that are … uh, related to each other.

To illustrate the point: if you had a brother, your mother would be the ‘key’ that forms the relationship between you and your brother.

With this analogy in mind, we can say that a relational database stores and tracks data by establishing relationships by using ‘keys’ (in this case, your mother) that are consistent between two pieces of information – you both have the same mother.

key_relationship.gif

Popular relational databases include:

· MySQL (often used with PHP because it’s free)
· Oracle
· Microsoft SQL Server

WHAT ARE VIRTUAL CONTAINERS?

We all know that it’s much easier to store and find stuff/things (in your home) if you put the stuff into boxes and then label the boxes … much better than just leaving all your junk on the floor.

Though naturally a messy bunch, nerds have picked up on that fact, and realized that computer information should also be stored in boxes (virtual containers) that are labeled. In a relational database, we call these ‘boxes’: tables.

In a nutshell: the virtual containers in relational databases are called ‘tables’ and information is stored in tables.

MORE ABOUT TABLES

Database tables are virtual containers designed to hold and organize data. In many ways they look like spreadsheets where database tables have both rows and columns.

The difference between a spreadsheet (like Excel,) and a relational database table, is that the spreadsheet is designed (has built in capability) to manipulate data for the purposes of presentation – creating charts and reports etc.

Where on the flip side, a database table is designed (has built in tools/capability) to organize and maintain information and it can hold much, much more information than a spreadsheet.

So yes, you can store information in a spreadsheet, but it lacks many capabilities (and capacity) that you would find in a database.

We will learn more about the makeup of a table (purpose of the rows and columns) when we actually build one.

THE ‘RELATIONSHIPS’ IN RELATIONAL DATABASES

As I mentioned above, a relational database stores information in tables (the virtual containers) and then creates relationships/connections between the tables (and thus the data that is stored in the tables.)

This system/method of storing information (by creating relationships,) is efficient because of a few reasons; the most important being is that this style of storing information (in tables that are related to each other,) helps to prevent information from being duplicated needlessly.

A FUNDAMENTAL PRINCIPLE OF DATABASE DESIGN

One of the fundamental rules in database theory/design, is that information should not be duplicated:

… if you have multiple copies of the same information floating around, it takes up more disk space and can easily become a nightmare to organize.

By storing information in different tables, and linking that information to each other (that are related,) you avoid duplicating information. This will become clear when we actually build our first database … I know (that for now,) many of you are probably unclear about a few things … have faith, it will come!

You learn more about databases and MySQL in the MySQL section of the site.

Thanks,

Stefan Mischook

The mini PHP crash course

Wednesday, July 5th, 2006

When PHP was first invented, it was short for:

‘Personal Home Page’

Then later (to make it seem fancier,) the nerds in charge of PHP, changed their minds and said the ‘PHP’ was a recursive acronym for “PHP: Hypertext Preprocessor”. Whatever PHP stands for, it is the most popular web scripting language today.

PHP allows you to create dynamic web pages easily and quickly. It is easy to learn and once you get the basics down, you will progress quickly and start creating some useful PHP scripts.

In non-geek terms: PHP is a programming language that runs in conjunction with a web server (ex: APACHE) that allows you to create web pages that change automatically. Examples of such include guest books, discussion boards, shopping carts … and so on.

I’m not going to try and teach you PHP here, but I thought it might be fun for you to see what it looks like.

PHP is very simple to use; the first thing to note is that PHP is embedded into HTML. That is to say, that PHP code is intermingled with your HTML code:

<html>
<head>
<title>Example</title>
</head>
<body>

<?php

echo “Hi, I’m a PHP script!”;

?>

</body>
</html>

The PHP code is enclosed in special start and end tags that allow you to jump into and out of “PHP mode”.

The special start tag is:

<?php

And the special end tag is:

?>

Anything in-between these special tags is processed by the PHP engine.

WHAT IS THE PHP ‘ENGINE’?

In a nutshell: The PHP engine is just a program that knows how to read and process PHP code. In the above example we are telling the PHP engine to do something very simple: print “Hi, I’m a PHP script!”.

In PHP (like in all programming languages,) there are special keywords that tell the PHP engine to do something.

In the above example we use ‘echo’, a special keyword/command that tells the PHP engine to print something to the HTML page.

So now you know PHP pages are just like HTML pages, except that they have special PHP code in places surrounded by the special PHP start and end tags. Oh yeah, PHP pages have the extension (that is to say: end with the letters) ‘.php’ rather than ‘.html’.

So if you have an HTML page called: ‘books.html’ and you wanted to add some PHP code into the page to for example, grab a list of books from a database, you would first have to change the page name to: ‘books.php’ and then insert the PHP code into your page.

You need to rename any html pages that have PHP code in them to ‘.php’, so that the PHP engine knows that there is PHP code in there.

Finally, you cannot run PHP pages unless your server has PHP installed. This is very likely since PHP is free for everyone, and runs on both Windows and non-Windows servers like Linux.

Conclusion:

This was just an ultra-quick introduction to PHP where for many of you, some things will probably be hazy. Don’t worry, there are many more articles and videos here that will clear things up.

Stefan

Database driven websites: what are they and how are they built?

Wednesday, July 5th, 2006

When I was beginning web design and web programming years back, I remember all the confusing terms, technologies, and concepts that were floating around that just made it that much more difficult to wrap my head around the whole web thing.

With that in mind, I thought that it might be a good idea to write a few short and (hopefully) sweet articles that will help people get a clearer understanding of what’s out there and what can be done with it.

This article will attempt to demystify database driven web pages … also called ‘dynamic web pages’ or websites. Don’t worry, I am not going to go into any painful mega-geek details about how to create dynamic web pages, instead I will give a brief overview to help you understand:

  1. When you would need to build dynamic web sites.
  2. What tools you have available to build them.

WHAT ARE DYNAMIC WEB PAGES?

To understand dynamic web pages, you have to understand normal or in other words ’static’ web pages.

Typical non-dynamic web pages do not change every time the page is loaded by the browser, nor do they change if a user clicks on a button. The only change that you will see in static web pages is to see them load and unload, like what happens when you click on a hyperlink.

In a nutshell:

static web pages (normal pages you build) always look the same and the content never changes unless you load a new page or you change the page yourself and upload the new version of the page to the web server.

Dynamic pages do the opposite, they can change every time they are loaded (without you having to make those changes) and they can change their content based on what user do, like clicking on some text or an image. (I am not talking about loading a new page!)

DATABASE DRIVEN WEB PAGES

One of the most common types of dynamic web pages is the database driven type. This means that you have a web page that grabs information from a database (the web page is connected to the database by programming,) and inserts that information into the web page each time it is loaded.

If the information stored in the database changes, the web page connected to the database will also change accordingly (and automatically,) without human intervention.

This is commonly seen on online banking sites where you can log in (by entering your user name and password) and check out your bank account balance. Your bank account information is stored in a database and has been connected to the web page with programming thus enabling you to see your banking information.

Imagine if the web page holding your banking information had to be built traditionally (that is by hand,) every time your bank balance changed! Even a thousand monkeys working 24/7 drinking 5 cups of coffee a day, would not be able to keep up!

Hopefully you are starting to see why you would want a database driven site: you would want it if your information changes very often, just like in a banking site.

Database driven sites can be built using several competing technologies, each with it’s own advantages. Some of those technologies/tools include:

  1. PHP
  2. JSP
  3. ASP
  4. PERL
  5. Cold Fusion

To continue …

Database driven web site programming can also be called (or characterized as): ‘server side programming’. The reason it is so called is because the ‘action’ or magic that allows the web pages to connect to the database is actually taking place on the server.

This is what happens:

each time a dynamic web page is about to be sent to the browser, the server automatically builds the page and sends a standard HTML page to the browser.

The server ‘knows’ how to build the page by following the instructions provided by the programmer. This is different from say JavaScript (think drop down menus or alert boxes) that runs strictly in the web browser.

At this point many people are getting very confused, the confusion lies in the difference between server side programming (database driven web pages) versus client side programming (JavaScript, AJAX).

CLIENT SIDE PROGRAMMMING: The other type of dynamic web page.

Client side (that is to say: in the browser) or what is commonly called DHTML … dynamic HTML.

DHTML is basically taking HTML and JavaScript (sometimes VB script) to make the web page change it’s own content (as far as the viewer is concerned) without having to reload or load a new page.

Examples of DHTML would include drop down menu’s, ‘floating’ images that hover over the rest of the page etc … if you look around, you will find plenty on the web.

Note: The name DHTML has been replaced by the term ‘DOM SCRIPTING’. It’s pretty much the same stuff (programming in the browser to make things happen dynamically,) but DHTML has a little bit of a bad wrap from the late 90’s, so more people now refer to it as ‘DOM scripting.’

-

Hopefully now you have basic conceptual understanding of dynamic web sites, DHTML and database driven web sites. I tried to present the information in a non-geek way so as to not confuse.

The downside of this simple approach is that I am not being 100% precise … some geeks out there may point out one or two items that are not dead on. But don’t worry, my points are not in any way wrong.

Suffice it to say that this was an introduction to the topic.

What is PHP?

Wednesday, July 5th, 2006

PHP is a very popular web scripting language and engine that allows you to create dynamic web pages easily and quickly.

It is easy to learn, so once you get the basics down, you will progress quickly and start writing some useful scripts.

In non-geek terms:

… it’s an engine that runs in conjunction with a web server that allows you to create web pages that change – examples of such include guest books, discussion boards … and so on.

Watch the PHP videos on this site to learn more.

Top of page  go to top of page