Developing PHP Applications with NetBeans and Eclipse

f you looked solely at the marketing for NetBeans and Eclipse, you might think you’d have no problems using either IDE with PHP, for example:

  • NetBeans: “A free, open-source Integrated Development Environment for software developers. You get all the tools you need to create professional desktop, enterprise, web, and mobile applications with the Java language, C/C++, and even dynamic languages such as PHP, JavaScript, Groovy, and Ruby. NetBeans IDE is easy to install and use straight out of the box and runs on many platforms including Windows, Linux, Mac OS X and Solaris.
  • Eclipse: “Eclipse is a collection of open source projects built on the Equinox OSGi run-time. Eclipse started as a Java IDE, but has since grown to be much, much more. Eclipse projects now cover static and dynamic languages; thick-client, thin-client, and server-side frameworks; modeling and business reporting; embedded and mobile; and, yes, we still have the best Java IDE.

Should PHP developers be impressed? You’ll find out in this article, which shows you the main PHP features of both NetBeans and Eclipse by walking you through a simple web application using each IDE. That way, you’ll be able to compare them, and decide for yourself if either meets your development needs. The downloadable sample web application acts as a search component for a virtual bookshop. Users will provide a book name, author, or ISBN, and the application returns search hits from a database. Implementing the application requires a range of technologies, including HTML, JavaScript (AJAX) and PHP, and a MySQL 5.0 database.

What You Need
  • NetBeans 6.5 for PHP
  • Eclipse PDT or Eclipse PDT 2.0
  • Java Development Kit (JDK) version 5 or 6
  • MySQL 5.0
  • PHP5
  • Apache HTTP Server 2.0

Author’s Note: I used Apache HTTP Server as the host server.

Introducing NetBeans IDE 6.5 for PHP

 
Figure 1. Downloading NetBeans 6.5 for PHP: Click the PHP row on the NetBeans download page.

I’ll start with NetBeans. To begin, download the NetBeans IDE from Sun (see Figure 1). To install it, just follow the installation wizard.

To run NetBeans for PHP, the standard Java Runtime Environment (JRE) is sufficient—you don’t need to install the full Java Development Kit (JDK). The latest version of the NetBeans IDE for PHP is 6.5. Some of its new features are:

  • PHP Source Code Editor
  • Remote and Local Project Development
  • Easy Code Navigation
  • PHP Debugging (you can inspect local variables, set watches, set breakpoints, and evaluate code live). The NetBeans IDE for PHP allows you to use XDebug, but using a debugger is optional. The recommended version is XDebug 2.0 as it is compatible with PHP5.
  • MySQL Integration

Creating the PHP Project

To begin implementing a PHP script/web application, you have to create a PHP project “stub”—an empty project that contains commonly used files and directories. IDEs typically use the “project” concept for any kind of application. NetBeans provides a dedicated wizard for configuring a new project. To create the sample booksPHP project, follow the steps below:

  1. Launch NetBeans.
  2. Select File ? New Project (this will open the New Project window).
  3. From the Categories panel, select PHP, and from the Projects panel, select PHP Application (notice that you also may choose to load and continue a PHP application begun outside of NetBeans). Click Next.
  4. On this page you enter a project name and location. For this project, in the Project Name field, type booksPHP, and choose a convenient location in the Source Folder field. Click Next.
  5. NetBeans supports running PHP applications on a local server (usually Apache HTTP Server), on a remote server (via FTP) or as a PHP script (using the PHP interpreter). As stated earlier, for this comparison, you’ll run the booksPHP application under Apache HTTP Server. Therefore, select the the Local Web Site item from the list. Next, enter the application’s URL in the Project URL field. Typically, the URL will be something like http://localhost/…. For example, for this project the URL might be http://localhost/php/booksPHP/ (obviously, you’ll need to adjust this URL for your particular configuration). Because you’re planning to run project on a local server, you need to provide a runtime location where NetBeans will copy the application source (which it does automatically to run the project). To do this, select the “Copy files from Sources Folder to another location” and specify the location in the “Copy to Folder” field (e.g., C:Program FilesApache GroupApache2htdocsphpooksPHP). Obviously, this action is necessary only when the project home folder and the local server home folder are different!
  6. Click the Finish button to close the New Project dialog.
Author’s Note If you choose to run the PHP application as a script, then you must indicate the location of the PHP interpreter (php.exe). Alternatively, if you choose to run on a remote web site (FTP) then you must enter a valid FTP connection, an upload directory, and an upload method.

At this point, NetBeans generates the project. You should see something like Figure 2.

 
Figure 2. Generated Project: After completing the New Project wizard, you’ll see the generated project “stub” appear in the NetBeans IDE.

Implementing the Project

With the project in place, you’re ready to begin implementing the booksPHP functionality. You’ll need some HTML for the presentation layer, some JavaScript to implement AJAX, and some PHP and database code for the business logic and persistence tasks. Because the application requires all the technologies in symbiosis, you’ll get to explore how well NetBeans handles each (with a focus on its PHP support).

Building the HTML Interface

Most of the HTML for this project resides in the index.php page, which NetBeans automatically created in the project stub. NetBeans lets you add HTML elegantly through the Palette tool. If this tool is not visible, you can activate it from the Window ? Palette menu. The Palette offers shortcuts to all the main HTML tabs, which you use by simply dragging-and-dropping the elements you need.

 
Figure 3. NetBeans Code Assistant: The Assistant provides help when inserting tags manually.

NetBeans require you to provide specific configurations for some tags before it adds them. For example, when you drag a

tag, you’ll be prompted for the number of rows, columns, and so on. I won’t go into further detail here—creating HTML code in NetBeans is pretty much a walk in the park. Therefore, use the Palette and drag and drop elements to modify the index.php as shown in Listing 1.

Some tags (such as

Overview

The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS

©2023 Copyright DevX - All Rights Reserved. Registration or use of this site constitutes acceptance of our Terms of Service and Privacy Policy.

Sitemap