Recently in php Category

Inside the Programming Castle

The more I learn about programming for the Web, the more it seems like everything is about the DATABASE. PHP just happens to be the tool we use to shuttle data back & forth .. to & from the database. PHP also lets you modify the data going back & forth .. in seemingly unlimited ways.

Castle of Computer ProgrammingEvery once in a while, I catch a glimpse of the power available in learning to wield programming languages. Very brief glimpses, cuz I am just a beginner.

Interestingly, these glimpses always come while I'm learning how to use PHP to access and manipulate data going into or coming out of a relational database (MySQL).

The coolest part of these glimpses .. is that they really do give me the sense that the power available in programming is truly UNLIMITED (.. limited only by your imagination).

I mean, computer programming is designed to use (work on) a computer. By that I mean » a CPU and memory, which itself mimics how the human brain & human memory works. So there's this self-reflexive thing going on in the background (or underneath) .. which is itself a little trippy. What are the limits of the human mind?

Hard to describe, cuz I'm still just a programming n00b (.. tho I continue to make progress). But the promise of unlimited creative power is very seductive. Can hear it calling my name.

The programming gods however, do not freely surrender the keys to this unlimited creative power. No, sir. There's a price to be paid.

In researching how our brains learn, it seems we find it easier to learn new-things that we can relate to things we already-know.

The problem (I've found) is that learning how to program does not readily lend itself to other things we might already-know. Rather, it's like having to build a whole new conceptual world .. from scratch. In other words, it takes longer. And requires more effort, in the form of memorization.

I actually went back and reviewed the material covering basic concepts .. especially the section on user-defined functions() .. after finding I kept having questions about material I already covered. I'm talking about after I began studying Object-Oriented Programming (OOP), which is the focus of Beyond the Basics.

First Peek into Object-Oriented Programming (OOP)

Took my first peek today into Object-Oriented Programming (OOP). This is something I've postponed until good-n-ready .. cuz I heard OOP's concepts can be difficult to digest, especially those introduced at the outset.

PHP logoI'm currently reading the Gilmore book (among others). Jason says (.. in chapter 6, under heading labeled » Benefits of OOP):

"It is the most powerful programming model on the planet."

Uh, actually he said it's » the most powerful programming model YET DEVISED. I substituted the phrase on the planet for dramatic effect. =)

Same thing. So you can see why this statement got me all hot-n-bothered. [ # Tho Nigel said OOP is not very different. ]

The flip-side of OOP is called 'procedural' programming. I reckon it'd be better for me to learn OOP before becoming too indoctrinated into the Procedural method. Less to unlearn this way. You know how difficult it can be sometimes to change-over to a new paradigm (way of thinking) .. once you've become comfortable with your current method. Old dogs & new tricks.

The OOP model shifts the focus away from (conceptually) a program's procedural events .. to the REAL-LIFE things the programming model represents.

This modeling-of-real-life lends itself (I've found) to making comparisons with how programming applies to REAL-LIFE itself (.. and vice versa).

Sorta meta-physical stuff .. which I won't delve into right now. But thought-provoking nonetheless, and maybe worth discussing some other time.

The focus on REAL-LIFE entities (or 'objects') tends to make programming with OOP less obscure .. than the regular procedural method .. which mimics a foreign language.

Regarding OOP being conceptually daunting .. here's a statement I had to read several times in order to grasp (.. we're still talking about the advantages of OOP):

The developer can change the implementation of the application without affecting the object user because the user's only interaction with the object is via the interface.

So no, it's not rocket science, but the going early on is pretty slow indeed. But it's also very rich, which makes it rewarding. [ # I've heavily marked-up the first few pages of this chapter, as ideas & concepts were exploding all over the place. ]

[ Today's entry could be subtited » The Database Room. ]

Easy to confuse the term 'database' with the software that runs one .. which is actually a 'RDBMS' » Relational DataBase Management System. I've used the term 'database' myself (many times) when what I actually meant was » RDBMS.

MySQL Relational Database Management SystemOkay to use the term 'database' generically, I suppose (.. to refer to its parent software), long as you're aware you're doing it. (Which I wasn't.)

Heck, even MySQL refers to the software it produces as a 'database.' (But it's actually a RDBMS.)

Interesting how sharply the (conceptual) line cuts .. where none existed only a short while ago. Cool to watch programming concepts take form.

A 'database' is a simply collection of tables .. similar to what you find in a spreadsheet. Whereas an RDBMS is the software that powers/runs the actual database.

Of course, I am FAR from being a database guru. (N00b is more like it.) But from what I can see, DATABASES look pretty cool (*).

[ I don't know much about RDBMS's, other than the software seems to function similar to the way a web server works, such as » Apache or LiteSpeed.

The 'relational' part seems to refer to TABLES, which can be 'related' to one another, in any way you like, but only when you explicitly specify the relation.

The database for the Drupal CMS, for example, contains 68 'related' tables. Bigger and more complex applications tend to have more tables. ]

(*) My background contains some mechanical engineering, so that's what I tend to use as a conceptual point of reference. It happens on its own. Here's what I see (» a physical analogy):

»» The Database Room

A good-sized ROOM. I call this » The Database Room. It's empty except for BOOKCASES .. on 3 of the 4 walls .. BOOKCASES that run both wall-to-wall & floor-to-ceiling .. all divided into many perfectly square little cubes.

The only other thing in the room sits mounted to a circular pedestal in the center » a big, shiny, mechanical ARM (made of Inconel stainless-steel) .. which both deposits-items-into & retrieves-items-from the bookcase .. which it does both quickly & efficiently.

Running into the room from the outside is a conveyor belt. (Black, of course.) The conveyor runs both to & from the big mechanical arm. Deftly the arm grabs packages from the conveyor and places them into their designated boxes/cubes (.. in the bookcase). It also retrieves requested packages from other cubes and places them on the outgoing conveyor.

My foray into the world of programming continues with PHP. Several readers wrote to recommend a book. All suggested the same title (by Luke & Laura). One even offered to send his used copy.

PHPEasy to see why they like it so much. The reading flows. Being the 4th edition, the editors had plenty of time to polish the text. It's enjoyable to read a well written book.

If you search Amazon Books for the query » 'php mysql,' this is the title that tops the (long) list returned. Published by Addison-Wesley, who have a reputation for releasing quality titles.

The book, as you might expect, goes into more detail than the video tutorial I was watching. Now that I have a feel for the language, these details are falling into place.

For example, they introduce & discuss the object model in Part I (chapter 6). Object-oriented programming (OOP) supposedly represents a new way of thinking, which differs from the old 'procedural' method.

I especially like how they point out 'common mistakes' (.. cuz I make them all).

Every reference I've ever read on the subject of PHP (including this book) always begins by noting how PHP allows you to serve DYNAMIC web pages (*.php), as opposed to 'static' pages (*.html), which don't change (.. unless you change them yourself).

PHP allows you to craft pages that change according to virtually any criteria you can imagine .. which is what makes it so powerful and useful. The book puts it this way:

If you've built websites using plain HTML, you realize the limitations of this approach. Static content from a pure HTML website is just that--static. It stays the same unless you physically update it. Your users can't interact with the site in any meaningful fashion. Using a language such as PHP and a database such as MySQL allows you to make your sites dynamic: to have them be customizable and contain real-time information.

MySQL databaseBut the fact remains that web authors still need to generate quality content. No matter how you might happen to retrieve & arrange & display the data stored in your database, the content is only as good as what goes INTO your database.

No amount of programming wizardry will turn krappy, poorly written content into a silk purse. (Wouldn't it be great if it could?) That's the thing staring me in the face, sobering my lofty techno esthusiasm.

Finally found a reason to deploy PHP myself. Pretty stoked about it, too. As my studies continue, I'm sure there will be more such programming discoveries .. but today I grok'ed the beauty and the power of the » PHP include() functon [.. and its more restrictive cousin » require() ].

PHPYou might recall last year, how excited I was to learn how to use Dreamweaver Templates.

They allow you to change/update a single file (template) and have that change applied to EVERY webpage that is based on that template.

I even wrote a guide on how to use them that has become surprisingly popular » Rad Guide to Dreamweaver Templates

Dreamweaver Templates are similar to how CSS works, which allows you to change the look-n-feel of your entire site by editing a single file.

The ONLY PROBLEM with Dreamweaver Templates is that they require you to UPLOAD all the changed files (.. to your server). Which kinda suks. (Depending on how many files are affected by the change.)

Not so with the PHP include() function, which works more like CSS. In fact, it works exactly like CSS in that respect. Meaning, you only have to re-up a single file.

Continuing to learn how to program with the PHP language. As a 'First PHP Project' the course is taking me thru the steps of designing & building a Content Management System (CMS). From scratch.

PHPI've long been interested in CMS'es (e.g. Drupal + Joomla + MODx) .. from a USER and Administrator standpoint. Approaching it from the developer's perspective has been very enlightening.

From a developer's point of view, a CMS can be reduced to two main functions:

  1. get data INTO a database (.. via autheniticated users logged into the staff area)
  2. retrieve data FROM the database (.. and display it on the web looking pretty, styled with CSS)

Whenever I've installed a CMS myself (such as Drupal or MODx), I've always first CREATED a database (in cPanel) .. with 3 specific things:

  1. name of database
  2. user_name
  3. password

But I've never created any tables. (A database consists of a collection of tables.) When you *install* any CMS (such as Drupal), the installer connects to the database specified (using the 3 pieces of info mentioned above) and creates all the tables for you. (Drupal, for example, will create 68 tables in your virgin, tableless database.)

But .. when you design & create your own CMS (from scratch), you have to design & create all the tables yourself. (A new experience for me.)

The tool-of-choice for rolling your own tables in/for a MySQL database is » phpMyAdmin. Configuring the database structure with tables is the first step in creating a PHP-based CMS from scratch (.. after 'blueprinting' the project based on goals and desired features).

Rad Intro to SQL & Databases

My study of the PHP programming language has taken me to » DATABASES, and how to manipulate them using SQL .. specifically MySQL, since that's the database used by most web-based applications.

MySQL databaseThe data stored in most databases is manipulated using the Structured Query Language (or SQL - pronounced ess-cue-el or see-kwul) to perform functions such as » create, read, update and delete.

It surprised me to hear the importance given to databases. A database has the ability to supercharge a PHP application. Without a database, a PHP application would not be nearly so powerful.

All Content Management Systems (CMS), such as Drupal, Joomla, and MODx .. work in conjunction with (require) a database. So do blogs, such as Movable Type and WordPress.

Back when I interviewed for that job last summer, they asked some very basic SQL questions. And I think it was my lack of experience in this area (more than anything) that disqualified me. They were looking for the ability to craft a basic SQL statement such as:

SELECT * FROM table_name WHERE column_name = 'some_text' ORDER BY column_name ASC;

PHP has long been designed to work seamlessly with databases, and this is one of the things that makes it so powerful.

Databases contain tables. A database is a collection of tables. My installation of Movable Type, for example, has 34 tables. MODx has 57 tables. Drupal has the most with 68. And all these tables are 'related'. Hence the term » 'relational' database.

Netbeans IDE for PHP Development

Installed Netbeans, an open source IDE (integrated development environment). An IDE is a program (application) designed to help programmers develop their applications. (« Kinda reflexive, no?) Heard about it when I asked the PHP programmers at MODx CMS what IDE they were using. Their answers surprised me.

Netbeans logoAlways thought Netbeans was solely for Java development. (You know .. beans = coffee = java.) Not so, apparently.

Been using Aptana Studio last few months. I like Aptana, but now I like Netbeans better.

I'm not savvy enough to use these powerhouse IDE's to anywhere near their full potential. For what I'm doing (learning), I could easily get by with Dreamweaver (which I use for web design), or even Notepad++.

But I'd like to become familiar with a few of the main players, which include » Zend Studio, Eclipse+PDT, Eclipse+Zend, PHPEclipse, Komodo, phpDesigner, phpEdit & phpED. At least, get a flavor for them. And I gotta write my code somewhere, right?

Before you can install the Netbeans IDE, first gotta install the Java Development Kit (JDK). Fortunately, you can download both programs in a » single installer (140 MB).

If a good installer is any indication of program-quality (.. like a good salad at a restaurant is often an indicator of a good main meal to follow), then Netbeans should be solid, cuz the installer is pretty slick.

Heck, they even have their own downloader (.. which rocks).

After the install, Netbeans will prompt to update a few files. (Nice.) After the update, first need to » install the PHP plug-in. (The instructions omit this step.)

Gaining Traction with PHP

Finally learned enough about PHP programming that my studies are gaining traction. 'Traction' is defined as the ability to connect new information to things previously learned .. instead of filing away the discrete bits for another day (like I've been doing). New practice-examples have been incorporating many of the principles I previously learned.

PHP Satisfying feeling .. like I've begun moving forward, making real progress. The pieces of my PHP puzzle are starting to fit together.

Up to this point, it felt as if my studies were based on little more than blind faith .. cuz I couldn't see how things I was learning about the language would work for me. That picture is now beginning to take shape.

I'm even starting to ask decent questions .. much more sophisticated questions than I used to ask. (The ability to ask good questions should not be underestimated.)

Plus I play-around with the code, seeing what happens if I try different things. This is one of my favorite parts of learning.

One of the reasons I began to learn PHP was cuz I wanted to be able to customize the new MODx Revolution Content Management System (CMS, currently at RC1, released just today), which is written in PHP.

But it appears that learning PHP does not necessarily translate into mastery with a PHP-based CMS. Learning a CMS, some say, is like learning a whole new language. (Hard to believe, no?)

For example, I just received an email from E-dawg [ .. who turned 26 today. I told him 26 was a good age cuz that's how old Einstein was when he published his papers in Special Relativity and mass-energy equivalency, known as E=mc². ] He has always said that learning PHP is easy. But today he said:

Computer Programming | A Novice Reflects

| 1 Comment

Been learning to program. Woohoo! Previously I spent considerable time learning *about* programming, particularly the pro's & con's of the various languages (.. something I enjoyed). Now however, I'm focused on learning the actual nuts-n-bolts of coding. Very different experience. More so than I would've imagined.

Aptana StudioSomething shifted today. Programming used to seem like something done at a desk 10-steps away (so to speak) .. by others, at a distance. Today it became something done here on my laptop.

I can now see what others meant when they suggested I 'just start' .. no matter what language I happened to choose.

Seems many of the initial concepts introduced to the aspiring programmer (such as data types & logical operators) apply to most programming languages. So learning these concepts is what's really important .. more than the syntactic details of any particular language.

Also seems like I was always searching for a conceptual framework upon which to begin learning a language. Hooks upon which to hang the things I would learn. A file system into which I could deposit & organize this information.

Finally found that 'framework' in (I'm almost embarrassed to say) » a 'Dummies' book (of all places), where the author asserted that programming was similar to writing a recipe, where you document the various steps required to fix your favorite dish.

That made sense to me. It was something I could relate to. Moreover it marked the point at which I quit learning 'about' programming & programming languages and began to actually focus on learning the nuts-n-bolts of a particular language.

Programming as a recipe. The recipe paradigm. Simple concept. Simple usually works best. (For the novice.)

Many courses and books use the 'don't-be-limited-by-the-programs-others-write' argument as their reason for learning computer programming. But that approach never really resonated with me. I never felt limited by the programs written by others, seeing there are so many good ones to choose from.

About this Archive

This page is an archive of recent entries in the php category.

nietzsche is the previous category.

programming is the next category.

Find recent content on the main index or look in the archives to find all content.