drop down joomla login module
26
Thu, Dec
0 New Articles

PHP 1: What You Need to Know Before You Start

Web Languages
Typography
  • Smaller Small Medium Big Bigger
  • Default Helvetica Segoe Georgia Times

So you're a great RPG programmer. Is that enough? Maybe not.

 

So, here you are, an RPG professional, all dressed up and ready to go. You can code up RPG real good, even some ILE. Got all that CL and DDS stuff mastered, but darned if people aren't saying that isn't enough. You've got to expand your skill set they say, learn a Web language. Don't you know that everything's going to be on the Web next month?

 

There are a number of Web-oriented languages out there but, for my money, PHP is as good a place to start as any. It's sure as heck easier to learn than Java, so why not?

 

But where do you start? Normally I might say "with some simple code," but there are a few things you should know about PHP before you even do that because, in some ways, PHP is very different from RPG, and you have to understand those differences before you get in the water.

Getting Started with PHP

I guess I will start by saying that PHP is not that hard. But then, it's not that easy either. I mean, what do you want me to say here? If I say it's hard, then some people won't even try it. If I say it's easy, then the first roadblock that folks come to will overwhelm them because their expectations were so high for breezing through this. PHP can do some very complex things. And you can approach PHP from an object-oriented point of view. But you can also do a tremendous amount in PHP with just a small set of commands that are used in a procedural manner.

 

So, if PHP is different from RPG, how is it different? Let's take a look.

Interpretive

Well, for starters, you don't compile PHP. It's an interpretive language, and it's rendered on the fly when you process the page that contains PHP code in the Web server. This makes some things simpler. There is no "PHP Compiler," so it doesn't have to be installed on your IBM i. The rendering engine that interprets the PHP instructions is a standard (and pretty much universal) part of every browser, so it's always there waiting for you. 

 

Of course, that also means that when you write it, there's no step that says "And here are all the syntax errors you need to correct." Instead, your PHP just won't work. The Web page will still display, but what you're trying to get to happen with the PHP won't happen. Now don't freak out; there are ways to debug code in PHP, good ways, but a syntax compile isn't one of them (although if you get the right code editor, that can really help).

Text Editor

And that brings us to the second thing. You write your PHP in a text file using a text editor, not in PDM or the other tools we use to write RPG and CL code. That is, there is no PHP source file or type on the i, although if you own Zend, it has a Windows-based IDE that runs on the i, which lets you create your programs there.

 

Instead, you'll create your PHP program on a text editor and it will be a text file, although instead of having a .txt extension, it will have a .php extension. You can use any text editor, even Notepad, but if you get something a bit more sophisticated, then it can actually help you with your writing (by automatically adding ending tags and such) and do some syntax checking.

PHP Happens in a Web Page

The PHP language is used to do something to a Web page. It may change the way it looks, it may get information from a data base and display it on the page, it may edit data and then write it to a data base, it can do all kinds of things. But it always does everything within the context of an HTML Web page.

 

To begin with, we'll actually embed the PHP code we write into an HTML Web page. That is, even though the file that you create to hold this program has a .php extension, you don't just create a PHP program. You create an HTML page, and in that page you embed PHP code. And then you give that HTML document a .php extension when you save it.

 

As you become more sophisticated with PHP, it's good form to actually put all of the PHP code in a .php file and then reference that file from the pure HTML (.htm or .html) file that describes the page. Either way, you can't just have a PHP file go to work; it is always within the framework of an HTML document.

 

Can you guess what I'm going to say next? Well, if you need to build your PHP code inside an HTML document, then you'll also need to learn at least a little HTML, hopefully HTML5. And, to be cool and display good Web form, you'll also have to learn a little CSS, preferably CSS3.

 

Wait a minute; don't walk away yet. It's not as bad as it sounds. In reality, it's quite possible that someone else on your team will do the HTML and CSS3, and just let you write your PHP code when they're done. Maybe. Sure, a definite maybe.  In fact, let's assume that's going to be the case, and if it isn't, you can be surprised later. Bottom line, we will only learn enough HTML to set up a very simple document. But just be aware that the more HTML and CSS3 you know, the better off you'll be.

Server Side, Client Side

RPG runs on the i. But PHP runs on the Web, within the Web server that holds your Web pages.  And that, where on the Web it runs, is a very important point. PHP is a server-side language.

 

HTML is a client-side language. It runs in the browser you're using. Make a change to the HTML code and run it in your browser and you see the change instantly. You don't need to actually upload that changed page  to the Web server; you can see the change on your browser immediately (although no one else will see the change until you upload).

 

But a server-side language executes in the Web server where your pages are really being stored. And that means that if you write a PHP program and then make a change to it, you can't see the change simply by looking at that Web page in the browser on your PC. You need to have access to a true Web server to test the change.

 

And the reason I'm telling you this? Because when you start to write a PHP program, you won't be able to just sit down at your PC and test it. HTML runs on the client side, so you can immediately see what happens when you make an HTML change. But it's a little more difficult with PHP. So, what can you do?

 

Well, one way you can test your PHP programs is to actually move them to the Web and then test them there. That's not completely crazy; many companies have both a test and a production Web site, but it gets a little annoying to have to load things out to the Web every time you want to check something out.

 

The way most people do it is to run a server instance on their PC—that is, a copy of Apache to simulate a server environment. WAMP (Apache, PHP, and MySQL for Windows) and MAMP (Apache, PHP, and MySQL for Mac) are two of the packages that you can download to your PC for free to do this.

 

Or—and you can probably guess this one too—you can use Zend. One of the extra things Zend does is provide a built-in Apache server, etc. so that you can create your PHP program and test it within the same single environment.

To Zend or Not to Zend

And speaking of Zend, let's just say a couple of things.

 

The first thing that people want to know is if Zend is free with the i. The answer is complicated but basically boils down to no; it's not free. You have to pay for Zend. You see, the Zend product consists of two parts: the Zend Server or Zend Core (which comes in two flavors: the full blown Zend Server that costs money and the Zend Server Community Edition, which is Zend Server Lite, but it's still quite functional and it's free) and the Zend Studio, which you always have to buy. So, no matter how you slice it, you have to pay something to use Zend.

 

The second question is, do you need to have Zend installed in order to do PHP? And the answer to that is no, but certainly life is a lot simpler if you have Zend.  For example, the Zend Server (including CE) comes with some extra IO routines that you can use to access both SQL and DB2 databases beyond what is in native PHP.   

Bottom Line

The bottom line is that you can get started with PHP right away, without having to convince someone to buy the Zend products. But you'll find life a lot easier if you download the free CE version of the Zend Server and take advantage of the features it offers. You can get it from the Zend Web site (www.zend.com). And the first thing you should do is get a little familiar with the PHP language.

 

Fortunately, there are a lot of resources out there if you want to learn PHP. Two that I think are particularly good are The IBM i Programmers Guide to PHP by Jeff Olen and Kevin Schroeder from MC Press (which also gives you an intro to Zend) or an online class Practical PHP Programming presented by TuxRadar (which is primarily oriented to Web programmers and doesn't mention the i ,but it's broken down into bite-sized bits for easy swallowing, covers more of the detail of the PHP language separate from the i,  and is very good).

 

That might be a good place to start, and in our next installment (two months from now), we'll look over the basics of creating a simple PHP program within an HTML page. Excitin', ain't it?

 

BLOG COMMENTS POWERED BY DISQUS

LATEST COMMENTS

Support MC Press Online

$

Book Reviews

Resource Center

  • SB Profound WC 5536 Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application. You can find Part 1 here. In Part 2 of our free Node.js Webinar Series, Brian May teaches you the different tooling options available for writing code, debugging, and using Git for version control. Brian will briefly discuss the different tools available, and demonstrate his preferred setup for Node development on IBM i or any platform. Attend this webinar to learn:

  • SB Profound WP 5539More than ever, there is a demand for IT to deliver innovation. Your IBM i has been an essential part of your business operations for years. However, your organization may struggle to maintain the current system and implement new projects. The thousands of customers we've worked with and surveyed state that expectations regarding the digital footprint and vision of the company are not aligned with the current IT environment.

  • SB HelpSystems ROBOT Generic IBM announced the E1080 servers using the latest Power10 processor in September 2021. The most powerful processor from IBM to date, Power10 is designed to handle the demands of doing business in today’s high-tech atmosphere, including running cloud applications, supporting big data, and managing AI workloads. But what does Power10 mean for your data center? In this recorded webinar, IBMers Dan Sundt and Dylan Boday join IBM Power Champion Tom Huntington for a discussion on why Power10 technology is the right strategic investment if you run IBM i, AIX, or Linux. In this action-packed hour, Tom will share trends from the IBM i and AIX user communities while Dan and Dylan dive into the tech specs for key hardware, including:

  • Magic MarkTRY the one package that solves all your document design and printing challenges on all your platforms. Produce bar code labels, electronic forms, ad hoc reports, and RFID tags – without programming! MarkMagic is the only document design and print solution that combines report writing, WYSIWYG label and forms design, and conditional printing in one integrated product. Make sure your data survives when catastrophe hits. Request your trial now!  Request Now.

  • SB HelpSystems ROBOT GenericForms of ransomware has been around for over 30 years, and with more and more organizations suffering attacks each year, it continues to endure. What has made ransomware such a durable threat and what is the best way to combat it? In order to prevent ransomware, organizations must first understand how it works.

  • SB HelpSystems ROBOT GenericIT security is a top priority for businesses around the world, but most IBM i pros don’t know where to begin—and most cybersecurity experts don’t know IBM i. In this session, Robin Tatam explores the business impact of lax IBM i security, the top vulnerabilities putting IBM i at risk, and the steps you can take to protect your organization. If you’re looking to avoid unexpected downtime or corrupted data, you don’t want to miss this session.

  • SB HelpSystems ROBOT GenericCan you trust all of your users all of the time? A typical end user receives 16 malicious emails each month, but only 17 percent of these phishing campaigns are reported to IT. Once an attack is underway, most organizations won’t discover the breach until six months later. A staggering amount of damage can occur in that time. Despite these risks, 93 percent of organizations are leaving their IBM i systems vulnerable to cybercrime. In this on-demand webinar, IBM i security experts Robin Tatam and Sandi Moore will reveal:

  • FORTRA Disaster protection is vital to every business. Yet, it often consists of patched together procedures that are prone to error. From automatic backups to data encryption to media management, Robot automates the routine (yet often complex) tasks of iSeries backup and recovery, saving you time and money and making the process safer and more reliable. Automate your backups with the Robot Backup and Recovery Solution. Key features include:

  • FORTRAManaging messages on your IBM i can be more than a full-time job if you have to do it manually. Messages need a response and resources must be monitored—often over multiple systems and across platforms. How can you be sure you won’t miss important system events? Automate your message center with the Robot Message Management Solution. Key features include:

  • FORTRAThe thought of printing, distributing, and storing iSeries reports manually may reduce you to tears. Paper and labor costs associated with report generation can spiral out of control. Mountains of paper threaten to swamp your files. Robot automates report bursting, distribution, bundling, and archiving, and offers secure, selective online report viewing. Manage your reports with the Robot Report Management Solution. Key features include:

  • FORTRAFor over 30 years, Robot has been a leader in systems management for IBM i. With batch job creation and scheduling at its core, the Robot Job Scheduling Solution reduces the opportunity for human error and helps you maintain service levels, automating even the biggest, most complex runbooks. Manage your job schedule with the Robot Job Scheduling Solution. Key features include:

  • LANSA Business users want new applications now. Market and regulatory pressures require faster application updates and delivery into production. Your IBM i developers may be approaching retirement, and you see no sure way to fill their positions with experienced developers. In addition, you may be caught between maintaining your existing applications and the uncertainty of moving to something new.

  • LANSAWhen it comes to creating your business applications, there are hundreds of coding platforms and programming languages to choose from. These options range from very complex traditional programming languages to Low-Code platforms where sometimes no traditional coding experience is needed. Download our whitepaper, The Power of Writing Code in a Low-Code Solution, and:

  • LANSASupply Chain is becoming increasingly complex and unpredictable. From raw materials for manufacturing to food supply chains, the journey from source to production to delivery to consumers is marred with inefficiencies, manual processes, shortages, recalls, counterfeits, and scandals. In this webinar, we discuss how:

  • The MC Resource Centers bring you the widest selection of white papers, trial software, and on-demand webcasts for you to choose from. >> Review the list of White Papers, Trial Software or On-Demand Webcast at the MC Press Resource Center. >> Add the items to yru Cart and complet he checkout process and submit

  • Profound Logic Have you been wondering about Node.js? Our free Node.js Webinar Series takes you from total beginner to creating a fully-functional IBM i Node.js business application.

  • SB Profound WC 5536Join us for this hour-long webcast that will explore:

  • Fortra IT managers hoping to find new IBM i talent are discovering that the pool of experienced RPG programmers and operators or administrators with intimate knowledge of the operating system and the applications that run on it is small. This begs the question: How will you manage the platform that supports such a big part of your business? This guide offers strategies and software suggestions to help you plan IT staffing and resources and smooth the transition after your AS/400 talent retires. Read on to learn: