chapter 01 introduction to php

25
Introduction to the Introduction to the Concept of PHP Concept of PHP Chapter 1 MOHAMAD RAHIMI MOHAMAD ROSMAN 1

Upload: dhani-ahmad

Post on 15-Jul-2015

153 views

Category:

Data & Analytics


0 download

TRANSCRIPT

Page 1: Chapter 01   introduction to php

Introduction to the Introduction to the Concept of PHPConcept of PHP

Chapter 1

MOHAMAD RAHIMI MOHAMAD ROSMAN 1

Page 2: Chapter 01   introduction to php

What is PHP?What is PHP?

What this chapter covers:◦ Understanding what PHP can do◦ Is PHP difficult?◦ Is PHP safe?◦ Using the download files

PHP stands for PHP: Hypertext Preprocessor. PHP is a scripting language that brings websites to life in the

following ways:◦ Sending feedback from your website directly to your mailbox◦ Sending email with attachments◦ Uploading files to a web page◦ Watermarking images◦ Generating thumbnails from larger images◦ Displaying and updating information dynamically◦ Using a database to display and store information◦ Making websites searchable

MOHAMAD RAHIMI MOHAMAD ROSMAN 2

Page 3: Chapter 01   introduction to php

PHP is a server-side scripting language, like ASP

PHP scripts are executed on the server PHP supports many databases (MySQL,

Informix, Oracle, Sybase, Solid, PostgreSQL, Generic ODBC, etc.)

PHP is an open source software (OSS) PHP is free to download and use

MOHAMAD RAHIMI MOHAMAD ROSMAN 3

Page 4: Chapter 01   introduction to php

PHP File?◦ PHP files may contain text, HTML tags and scripts ◦ PHP files are returned to the browser as plain HTML ◦ PHP files have a file extension of ".php", ".php3", or ".phtml"

MySQL?◦ MySQL is a database server ◦ MySQL is ideal for both small and large applications ◦ MySQL supports standard SQL ◦ MySQL compiles on a number of platforms ◦ MySQL is free to download and use

PHP + MySQL◦ PHP combined with MySQL are cross-platform (means that you

can develop in Windows and serve on a Unix platform)

MOHAMAD RAHIMI MOHAMAD ROSMAN 4

Page 5: Chapter 01   introduction to php

Why PHP?Why PHP?

PHP runs on different platforms (Windows, Linux, Unix, etc.)

PHP is compatible with almost all servers used today (Apache, IIS, etc.)

PHP is FREE to download from the official PHP resource: www.php.net

PHP is easy to learn and runs efficiently on the server side

Where to Start? Install an Apache server on a Windows or Linux machine Install PHP on a Windows or Linux machine Install MySQL on a Windows or Linux machine Currently all this components can be found together, such

as EasyPHP and can be run on localhost

MOHAMAD RAHIMI MOHAMAD ROSMAN 5

Page 6: Chapter 01   introduction to php

How hard is PHP to use and How hard is PHP to use and learn?learn?

PHP isn’t rocket science, but at the same time, don’t expect to become an expert in five minutes. If you’re a design-oriented person, you may find it takes time to get used to the way PHP is written. Frequent practice is necessary to become an expert.

MOHAMAD RAHIMI MOHAMAD ROSMAN 6

Page 7: Chapter 01   introduction to php

PHP is written in plain text, so you don’t need any special authoring software. However, your life will be a lot easier if you choose a good script editor. I’ll offer some advice on what to look for. The other thing you need is a web server capable of understanding PHP.

MOHAMAD RAHIMI MOHAMAD ROSMAN 7

Page 8: Chapter 01   introduction to php

Choosing a good script editor for PHP

Although PHP isn’t difficult to learn, if there’s a mistake in your code, your page will probably never make it as far as the browser, and all you’ll see is an error message. So, although you can write PHP in Notepad or TextEdit, you’re much better off with a script editor that has at least the first three of the following features:◦ Line numbering: Most good script editors allow you to toggle on and

off the display of line numbers. Being able to find a specific line quickly makes troubleshooting a lot simpler.

◦ A “balance braces” feature: PHP uses parentheses (()), square brackets ([]), and curly braces ({}), which must always be in matching pairs. It’s easy to forget to close a pair. All good script editors have a feature that finds the matching parenthesis, bracket, or brace.

◦ PHP syntax coloring: Some script editors highlight code in different colors. If your code is in an unexpected color, it’s a sure sign that you’ve made a typing mistake.

◦ PHP code hints: This is mainly of interest to more advanced users, but some editors automatically display tooltips with reminders of how a particular piece of code works.

MOHAMAD RAHIMI MOHAMAD ROSMAN 8

Page 9: Chapter 01   introduction to php

Choice of Authoring SoftwareChoice of Authoring Software

Expert◦ Any authoring software

Intermediate◦ Macromedia Dreamweaver

Beginner◦ Notepad, because it will help the learners to memorize the syntax.

MOHAMAD RAHIMI MOHAMAD ROSMAN 9

Page 10: Chapter 01   introduction to php

Macromedia DreamweaverMacromedia DreamweaverMOHAMAD RAHIMI MOHAMAD ROSMAN 10

Page 11: Chapter 01   introduction to php

Deciding where to test your pages

Unlike ordinary web pages, you can’t just double-click PHP pages in Windows Explorer or Finder on a Mac and view them in your browser.

They need to be parsed—processed—through a web server that supports PHP. If your hosting company supports PHP, you can just upload your files to your website and test them there.

However, you need to upload the file every time you make a change. In the early days, you’ll probably find you have to do this often because of some minor mistake in your code.

As you become more experienced, you’ll still need to upload files frequently because you’ll want to experiment with different ideas.

The best way for a good PHP development is to set a local server on your computer.

MOHAMAD RAHIMI MOHAMAD ROSMAN 11

Page 12: Chapter 01   introduction to php

Setup Local ServerSetup Local Server

Requirement◦ Apache◦ PHP◦ MySQL

For this training sessions, I will be using EasyPHP that combine all the software.

MOHAMAD RAHIMI MOHAMAD ROSMAN 12

Page 13: Chapter 01   introduction to php

Programmer PathProgrammer Path

VB 6.0

MOHAMAD RAHIMI MOHAMAD ROSMAN 13

PHPPHPASPASP

C++C++

PHP Syntax is quite similar to C++ syntax. A good programmer should has basic knowledge on vb 6.0 and C++. This will help them to master both PHP and ASP language

Selecting the right path1. If you expert in VB 6.0, ASP is the best choice for you.2. If you expert in C++, PHP is the best choice for you.3. If you good in both language, using PHP will be a better choice.

Page 14: Chapter 01   introduction to php

What happens if you don’t What happens if you don’t have the necessary have the necessary knowledge? knowledge?

It’s ok because PHP language is easy to learn and memorize.

The trends at the moments is more towards the Open Source Software (OSS).

MOHAMAD RAHIMI MOHAMAD ROSMAN 14

Page 15: Chapter 01   introduction to php

Mambo, Joomla! And XoopsMambo, Joomla! And Xoops

Mambo, Joomla and Xoops are among the popular free PHP website

By using this kind of web software, web developer only need 5 minutes to create a website.

Amazingly, you don’t need a single PHP knowledge to handle this website, but if you are looking to create your own components, PHP knowledge is the things you should seek.

MOHAMAD RAHIMI MOHAMAD ROSMAN 15

Page 16: Chapter 01   introduction to php

CMSCMS

This Content Management System (CMS) is comprised of:◦ Modules◦ Components◦ Templates◦ Mambots

MOHAMAD RAHIMI MOHAMAD ROSMAN 16

Page 17: Chapter 01   introduction to php

PHP FilePHP File

PHP file is just a simple text file, with an extension of *.php.

MOHAMAD RAHIMI MOHAMAD ROSMAN 17

Page 18: Chapter 01   introduction to php

How to create PHP FileHow to create PHP File

1. Create a New Text Document2. Open a folder, go to TOOLS.3. Select FOLDER OPTIONS4. Select VIEW5. UNCHECK hide extensions for known file

types.6. Click OK

MOHAMAD RAHIMI MOHAMAD ROSMAN 18

Page 19: Chapter 01   introduction to php

MOHAMAD RAHIMI MOHAMAD ROSMAN 19

•Uncheck the box

Page 20: Chapter 01   introduction to php

MOHAMAD RAHIMI MOHAMAD ROSMAN 20

Create a new text document with txt extensions

Change the *.txt to *.php extensions

New PHP file successfully create

Page 21: Chapter 01   introduction to php

Where to locate your web files

All folder should be put into the following path:◦ C:\Program Files\EasyPHP 2.0b1\www\◦ This path is consider as a root folder for the localhost.

MOHAMAD RAHIMI MOHAMAD ROSMAN 21

Page 22: Chapter 01   introduction to php

Local HostLocal Host

To view your pages, notice the EasyPHP icon on your taskbar.

Right click the icon for menu.

MOHAMAD RAHIMI MOHAMAD ROSMAN 22

To create database

To view PHP webpage

Page 23: Chapter 01   introduction to php

Local HostLocal HostMOHAMAD RAHIMI MOHAMAD ROSMAN 23

• All pages and folder will be listed here.

Page 24: Chapter 01   introduction to php

AdministrationAdministrationMOHAMAD RAHIMI MOHAMAD ROSMAN 24

• The true potential of PHP is by using the database. This page is used to create a new database. MySQL work tremendously with the PHP

Page 25: Chapter 01   introduction to php

Creating New DatabaseCreating New Database

PHPMyAdmin Url◦ http://127.0.0.1/home/mysql/◦ Create a new database, ‘php’

MOHAMAD RAHIMI MOHAMAD ROSMAN 25