Archive for the ‘Beginners PHP Articles’ Category

My Killer PHP Learning Tips

Thursday, September 3rd, 2009

php logo

Hi,

Learning to program can be a frustrating process for a lot of people; especially for designer types wanting to learn a little PHP. The following tips should help a lot of you along the way to becoming a PHP nerd. My PHP learning tips:

1. Be patient:

Patience is a virtue, especially when learning to program. Don’t be discouraged if something doesn’t sink in right away. It will come with time.

2. Learn to write code on faith:

… That means writing PHP code that you may not fully understand. The process of actually writing out the code, seems to help the brain take it in.

3. Learning PHP programming is a lot like learning a sport; you can pick up stuff by sitting on the sidelines and watching, but you don’t really know what you’re doing until you actually get into the game. In PHP, that means actually writing code and not just sitting listening or reading about it.

4. Take a breather:

If something is not sinking in right away, move on to something else and come back to it later … actually, give it 24 hrs to sink in. I find that the brain will work on problems over night and almost magically, things that you could not understand the day before, will become obvious.

5. Try variations in your code:

Play with different ways of doing things, try to add variation to your code. If for instance you are learning something as simple as a conditional statement .. like the ‘if’ statement, try some examples with mathematical equations and then maybe try something using a function that returns a true/false value.

6. Break your code:

One of the best ways to learn any programming language is to purposefully break code. Why? Basically it comes down to seeing what type of error messages you get for certain types of mistakes in your code. In time, you will see that particular errors will give you consistent error messages. Once you know these, debugging code will be a lot easier.

I’ve found that breaking things on purpose and in a controlled manner, can really help down the road when you run into real errors, because you will recognize the error messages.

PHP vs. Perl vs. Java – a student’s question.

Monday, August 17th, 2009

Once and a while, I get a question from a student about PHP and programming that I use in a blog post … here we go again:

… you mentioned that you used to use mostly Java but have switched to mostly PHP. Would you recommend learning PHP as a primary method of creating dynamic web pages or is its strength in data base manipulation. I was learning Perl form processing which led me to your site when I was having trouble with mySQL, and I noticed PHP is very similar (at least in the basics) as Perl. Do you have much experience in using Perl to help create web pages and would you recommend using it at all?

About PHP vs. PERL vs. Java:

PHP is the way to go. Perl is a good language but it was not designed initially for web development – that functionality was added later.

Whereas PHP (which borrows from Perl btw) was designed specifically for web development, and so Perl is just clunkier compared to PHP when it comes to creating dynamic web sites.

I’ve used Perl in the past, mostly creating simple string parsing scripts and other little things. But I would NOT call myself an Perl programmer – so take that into consideration.

That said, I’ve always liked a common strategy used in Perl, where they generate static pages from dynamic code. For example, in our web designers directory, I used a Perl based directory script that uses that strategy.

… What’s interesting is that it generates the directory pages as static HTML pages. The advantage of this is that the directory itself is more portable and much less resource intensive because for the most part, the directory is just of pages that people just read … no need for them to be dynamically generated every time a user request it.

(more…)

Server Migration is Easy with PHP

Monday, July 13th, 2009

Recently we had to make an emergency move from our old servers (where we had been for 5-6 years) to our own dedicated server because of technical difficulties in the heads of the nerd’s who managed the servers killersites.com had been sitting on.

I will spare you the details of my server migration ordeal for now. What I want to point out, is that PHP (once again) has proven to be a great choice as the server side programming language.

PHP is consistent …

During this move, I had to deal with a bunch of web apps and scripts that included a nice buffet of technologies like:

- Perl
- PHP
- Java

.. Yes, the dreaded evil configuration hell that is J2EE!!

To make a long story short, migrating the PHP apps was a snap – copy over the files, set up the database and were off! On the other hand, I still have to get around to figuring out why the Perl and Java applications don’t want to run on the new server.

:(

PHP continues to rock, saving me time, money and headaches.

Stefan Mischook
www.killerphp.com

Programmers should learn to be language agnostic.

Monday, July 13th, 2009

In my last post I wrote about how Ruby’s early problems around 2006-2007:

- incomplete libraries
- difficult web server integration

.. had played a role slowing its adoption. The main thrust of the piece was to point out that despite the explosion of interest, Ruby and Rails had failed to make much of a dent relative to PHP in terms of usage. In fact, PHP is still far and away a much more popular language.

(more…)

PHP Video: always MySQL with PHP?

Wednesday, June 3rd, 2009

php video

Hi,

In this HD video (running time: 4:06), I answer a question put to me recently:

Should you always use MySQL as your database when working with PHP?

Yes, this is a beginners question, I know. Nonetheless, it is a legitimate question that I think is worthy of comment. In answering this question though, I briefly talk about the other database options you have with PHP.

The video:

MySQL with PHP

Note: I am using Youtube’s new HD streaming capabilities as an experiment. This is 720p video so you should have a fast connection to watch it, or some patience. If you find the video is stuttering, just press ‘play’, then pause it and then give it a minute or two to download.

Thanks,

Stefan Mischook

How to Build a Content Management System

Sunday, October 5th, 2008

OK, I just tricked you! This article is not going to teach you how to build a content management system with PHP from scratch.

Why not?

… Because building a content management system from scratch is (probably) a really dumb idea!! Now that I come to think about it, building any of the most commonly used software from scratch, is kinda stupid.

Things you should not build from scratch:

  • Content Management Systems
  • Blog Software
  • Forums
  • Directory scripts

The Top 3 Rules in Programming

The real estate business has a famous set of rules – the top three rules in fact:

  1. Location
  2. Location
  3. Location

The idea behind this rule, is to stress how important location is to a piece of property. In software development (programming), we have a similar set of key rules:

  1. Reuse
  2. Reuse
  3. Reuse

(more…)

SQL insert statements in PHP

Saturday, July 19th, 2008

Hi,

I’ve finally released my first video on using SQL statements in PHP pages. This is the next step after connecting to a MySQL database.

I hope you find the videos useful.

Stefan Mischook
www.killerphp.com

How to call functions from another class.

Saturday, July 19th, 2008

Many of my articles and videos are based on questions that I see popping up in the php forums or in emails sent to me personally.

Recently I was asked by someone how they could call a function found in one class, in another. This may seem like basic stuff to those of us who know … but please keep in mind, at one time, none of us knew anything!

:)

Anyway, here is my video on using a function from another class in a class.

Why build all your web pages in PHP?

Thursday, May 15th, 2008

I recently had this question put to me by a web designer who was considering the idea of using PHP pages in her websites:

“Why build all your pages in PHP … Why not use standard .html pages?”

She then expanded the question to:

“What I mean is…… what’s the benefit to building ALL sites in PHP?”

Note to uber-nerds: remember that this question is being put to me by a web designer who has never written software. As such the answer is tailored those who are new to programming.

I might tackle this question from another perspective if the question was put to me by an experienced developer.

PS: If you find my answer offensive to your nerd-sensibilities, you might want to read this.

The Answer:

By making all your web pages PHP pages from the start, you are basically leaving open the possibility of using PHP in your web pages at any time.

… You don’t want to (at some later date) have to go back and change your .html pages to .php. For example:

  1. my-product-list.html
  2.  
  3. … becomes:
  4.  
  5. my-product-list.php

Beginners should note, that you need to have .php extension on any web pages where you want to use PHP. Check out my basic PHP videos for details.

-

PHP can do a lot more than just talk to MySQL. One very common use of PHP is to create ‘includes’ … this will allow you to insert snippets of code in your pages from separate files. This is kinda like using external CSS files. So you can use PHP includes to say create your page footers.

You can learn more about PHP includes in my free videos.

In the end, by making all your pages php pages from the start, you will just have a more flexible website to work with since you will be able to access PHP’s power.

Stefan Mischook

www.killersites.com

NEW BASIC SQL TUTORIALS

Tuesday, April 1st, 2008

Hi,

I’ve managed to upload new video tutorials on SQL basics. At this point, I’ve covered the four big SQL statments:

  1. INSERT
  2. SELECT
  3. UPDATE
  4. DELETE

You can view the videos here: Basic SQL Statements Video Tutorials.

Now that we have that covered, my next videos will be on using PHP to connect to and work with MySQL.

Thanks,

Stefan Mischook

www.killerphp.com

BASIC SQL TUTORIAL

Monday, March 31st, 2008

Hi,

mysql-logo

I’ve just put up a new sub-section on SQL – the language of relational databases.

This is beginners stuff, so if you’re a know-it-all nerd, you can ignore this. On the otherhand, if you’re new to the database thing (mySQL for example) then these first couple of videos should help you get started.

Videos out so far:

- Introduction to SQL
- Introduction to the SQL ‘insert’ statement.

I plan on having a bunch of new videos out soon that cover:

  • The big four SQL statements.
  • The basics of database design.
  • The cardinal rules of database design.

My goal is to not turn you guys into database gurus, rather, I want to just give you enough so we can get you going with PHP and mySQL.

Thanks,

Stefan Mischook

www.killerphp.com

PHP Video Tutorials for iPods

Wednesday, February 20th, 2008

ipod-php-video-icon

Because of recent demand, I decided to release my PHP video tutorials in iPod format – that means they play on your iPod.

:)

… OK, you guys guessed that one.

These video were originally intended for viewing on a computer monitor, so some of the code examples will be harder to read since iPod screens are smaller.

Nonetheless, the discussions may be useful to watch on your iPod as you’re … say, on your way to work or school.

A small note: I’ve added some brief comments (in text) about each video, to give you a better idea of what you will find in the video before downloading it.

You can find the videos on the new iPod video page.

Thanks,

Stefan Mischook

PHP Sessions Video Tutorials – Part 3

Sunday, February 17th, 2008

This is part 3 (of 3) of my video tutorials that introduces PHP sessions to beginners.

php sessions video tutorial

The video:

PHP session video tutorial – part 3

Notes from the videos:

Session ID:

PHP sessions create a unique id that is passed on to the user by either a cookie or in the URL string. To be clear, the actual information tracked about the user is stored on the server, the cookie or URL string only contains the unique id that is automatically generated by the PHP session object.


How long do sessions last?

By default, sessions are set to last 24 minutes – although your hosting company could set this to any length of time they want. Once a session expires, the server deletes all information associated with that session. Sessions are kept active by the user hitting pages that have session enabled.

Remember that sessions are not meant as a long term storage solution, that is what databases are for.


Sessions are arrays:

Sessions are auto global associative arrays (on steroids) that can be accessed on any session enabled page. This is yet another example of why knowing arrays is so important in PHP … and in programming in general.

Sessions have to be declared at the very top of the PHP page!

To use session in a PHP page, it needs to be declared at the very top of the page, before anything else, otherwise you will get an error.

-

If any of the above points confuse you, all you need to do is watch the videos and it will all magically become clear.

:)

The video:

PHP session video tutorial – part 3

Thanks,

Stefan Mischook

www.killerphp.com

PHP Sessions Video Tutorials – Part 2

Friday, February 15th, 2008

This is the part 2 of 3 of my videos that introduces the beginner to PHP sessions.

php sessions video tutorial

In this video, I get into practical examples where we see basic PHP sessions in action.

PHP session video tutorial – part 2

Thanks,

Stefan Mischook

www.killerphp.com

PHP Sessions Video Tutorials – Part 1

Wednesday, February 13th, 2008

Hi,

I’ve just released a new beginners video tutorial that introduces people to PHP sessions:


PHP Sessions Video Tutorial

PHP sessions are one of the most important mechanisms in PHP because they solve a fundamental issue in web application development: keeping state on a user.

php sessions video tutorial

If what I just says confuses you, no worries, it’s explained in the video.

This is video 1 of 3 on sessions.

Thanks,

Stefan Mischook

www.killerphp.com

What Makes a PHP Web Application?

Wednesday, November 7th, 2007

Once and a while a get an email question put to me that I think many others are probably wondering about the same thing.

I got this email from Jordan:

Hi Stefan,

I am very interested in learning how to program, specifically with php. I went through all you videos which are excellent!

My main question is, after watching your videos and reading some tutorials I now understand the concepts such as variables, arrays,if statements etc., but have still have no idea how to put these together to create a web application.

I know exactly what I want the site to do but just have no idea where to begin. Where do I begin, is there something I can purchase that will guide me?

The simple answer to this is to just start writing code. Understanding PHP theoretically, is only the beginning of actually truly knowing it. Once you sit down and start writing code, things will seem to magically clear up as you go along.

(more…)

Video Tutorial: PHP conditionals

Monday, September 24th, 2007

PHP Video Tutorial

The following video teaches the basics of conditional statements in PHP; specifically the ‘if’ statement.

PHP conditionals video tutorial

Again, this video is for beginners to PHP and programming in general.

Note to uber-nerds:

If anyone complains to me that this video is to simple, I might hit you with a theoretical article on how aspects (as in aspect oriented programming) can be used to injects meta-data into your objects, without polluting the model.

:)

… Good old Java.

Stefan

Cannot load mysql extension error – Video Tutorial How To

Saturday, September 15th, 2007

I recently ran into the following error when trying to launch PhpMyAdmin from the WAMP icon tray menu:

phpMyAdmin – Error
Cannot load mysql extension. Please check your PHP configuration.

What does this mean?

In a nutshell, PHP cannot find the library (mysql.dll – on Windows) it needs to connect to MySQL.

How can you fix this?

  1. Use phpInfo() to find out what php.ini file PHP is using. It’s near the top.
  2. Go into your php.ini and enable the extension that loads the mysql.dll library.
  3. Set your Windows ‘Path’ to point to the directory where the mysql.dll is sitting.
  4. Restart Windows.

The solution (and more details) can be found in this video:

Tip: Try the full-screen mode for the video .. it’s pretty nice.

I hope you find this useful.

Thanks,

Stefan Mischook (All around nerd.)

www.killerphp.com

Installing PHP and MySQL on the Mac with MAMP

Friday, September 14th, 2007

In my beginners php videos, I recommended XAMPP as the way to easily install Apache, PHP, MySQL on a MAC.

Well, I just discovered something called MAMP at:

http://www.mamp.info/en/index.php

This nifty little application allows you to (really easily) install Apache, PHP and MySQL. You are provided with a standard DMG file that you simply drag to your applications folder.

MAMP has a pro ($) and a standard version … all programmers need (to do their development on their local machines,) is the free standard version.

Once installed you can start MAMP up (and thus Apache, MYSQL) as you would any other program … and this is what you get:

Mamp Control Panel

As you can see, you can start and stop the servers and tweak the MAMP settings (example: where Apache looks for web pages … the Apache document root etc).

The MAMP ‘Start Page’:

Like XAMPP, MAMP comes with it’s own ‘Start Page’ where you can access:

  • MySQL password information.
  • phpMyAdmin
  • SQLightManager

The Screenshot:

Mamp Start Page

Dashboard Widget!

But what’s even more cool, is that MAMP comes with a Dashboard widget:

Mamp Dashboard widget

Conclusion:

I am currently using MAMP to do some test on a PHP based CMS (Drupal) and MAMP allowed me to set up my Mac in about 5 minutes … maybe 4.

Stefan Mischook

www.killerphp.com

Why learn OOP in PHP – another take.

Friday, September 7th, 2007

php logo

Why learn OOP in PHP – another take.

For people new to OOP and are comfortable with ‘classic’ procedural php, you may be wondering why should you even bother to learn object oriented concepts … why go through the trouble?

The PHP world:

PHP is moving in an OOP direction. For example, many important PHP extensions like PEAR and Smarty are OO based. So, to really understand and use these frameworks properly, you need to understand object oriented PHP.

The functional/practical advantages:

For smaller projects, using object oriented PHP may be overkill. That said, object oriented PHP really begins to shine as the project becomes more complex, and when you have more than one person doing the programming.

For example:

If you find that you have say 10-20 or more functions and you find that some of the functions are doing similar things … it is time to consider packaging things up into objects and using OOP.

OOP and your career as a programmer:

OOP is the modern way of software development and all the major languages (Java, PERL, PHP, C#, Ruby) use this method of programming. As a software developer/programmer, it only makes sense (in terms of career,) to keep your skills up-to-date.

Besides making you a more valuable PHP coder, understanding OOP in PHP will give you knowledge (OOP knowledge,) that you will be able to take with you into other languages.

… When you learn OOP in PHP, you’ll learn object oriented programming for any OO based language.

You will find with time that creating OOP based PHP projects, will just make your life as a programmer much easier. As an added bonus, soon you will develop your own collection of reusable objects, which you will be able to leverage in other projects.

Finally, You will also find that OOP based PHP is much easier to maintain and update.

OOP Challenges:

OO PHP does present some challenges when you first start out because you’ll need to learn to think about your PHP projects in a different way: you will need to conceptualise the project in terms of objects.

More details …

One common way of starting an object-oriented project is to start by drawing up simple diagrams of your objects. As you begin to work with object diagrams, you will find that they help make developing OOP based PHP projects much easier.

Here are a few tips about drawing object-diagrams:

· Use a paper and pencil
· Draw boxes to represent each object
· In those boxes, list your methods and your properties
· Use arrows and lines between boxes to denote relationships (parent – child) between objects.

So if you have been sitting on the fence waiting to jump into OO PHP, now is as good time as any to get started.

Stefan Mischook

www.killerphp.com
www.killersites.com

Top of page  go to top of page