[plug] Learning PHP advice

Daniel Foote freefoote at gmail.com
Wed Feb 22 08:53:38 WST 2006


> I must agree with Patrick here. The php manual is VERY good,
> (especially compared to the perldoc...). Having  a local copy on my
> machine has been very useful, and I still refer to it, even though PHP
> is the language I work in most.
> I basically took my C/FORTRAN/Perl... knowledge, started coding php,
> looking up the manual for function names, and syntax, and it was all I
> needed! Of course, some other things, I've taken longer to develop,
> for example MySql PHP application's, which I do work in, but took
> awhile to work out the best approaches.


I've been programming PHP for a while now; I taught myself with the
PHP manual. I quite like PHP, it's a neat language, and allows you to
quickly build things. (But I am far from an expert...)

However, it's quite easy to turn PHP code into "spaghetti code" (as so
called by a colegue), when mixing PHP code and HTML. My solution to
this problem, which I only discovered in the last few months, is to
use a templating engine. I recommend Smarty - http://smarty.php.net.

Smarty is written in PHP and compiles templates down to PHP code, so
after the compilation (which is cached) the templates run really fast.
It seperates the "application logic" from the "presentation".

On the DB side, I would also recommend looking at PEAR
(http://pear.php.net). Again, this is written in PHP, and it contains
all sorts of very useful additional functions - the only one of which
I'm using is the DB layer. It's basically a DB abstraction. When you
use it, you can easily switch between databases - quite a few are
supported (at least MySQL, Postgres, Oracle, DB2, Access, and a few
others). In a project I finished a few months ago, I was able to
switch directly between Postgres and MySQL with no PHP code changes -
and only one change to a SQL query (to get around a Postgres
"difference").

The Smarty + PEAR + PHP combination has worked for me. Very well in
fact. I'm currently working on two projects using these things.

Now if I only had some "graphic design" skills to make the output not
look like some hideous abomination...

Have fun...

Daniel.



More information about the plug mailing list