PROGRAMMING WITH PHP & MYSQL
Syllabus
Unit-1: The Building blocks of PHP: Variables, Data Types, Operators and Expressions, Constants.Flow Control
Functions in PHP: Switching Flow, Loops, Code Blocks and Browser Output.Working with Functions: What is
function?, Calling functions, Defining Functions, Returningthe values from User-Defined Functions, Variable Scope,
Saving state between Function callswiththestatic statement, moreabout arguments.
Unit-2: Working with Arrays: What are Arrays? Creating Arrays, Some Array-Related Functions.Working with
Objects: Creating Objects, Object Instance Working with Strings, Dates andTime: Formatting strings with PHP,
Investigating Strings with PHP, Manipulating StringswithPHP, UsingDate and TimeFunctions in PHP.
Unit-3: Working with Forms: Creating Forms, Accessing Form Input with User defined Arrays,Combining HTML
andPHP code on a single Page, Using Hidden Fields to save state,Redirecting the user, Sending Mail on Form
Submission, and Working with File Uploads.Working with Cookies and User Sessions: Introducing Cookies, Setting a
Cookie with PHP,Session Function Overview, Starting a Session, Working with session variables,
passingsessionIDsintheQueryString,DestroyingSessionsandUnsettingVariabl es,UsingSessionsin an Environment with
Registered Users.
Unit-4: Working with Files and Directories: Including Files with inclue(), Validating Files, Creatingand Deleting Files,
Opening a File for Writing, Reading or Appending, Reading from Files,Writing or Appending to a File, Working with
Directories,OpenPipestoandfromProcessUsingpopen(),RunningCommandswit
hexec(),RunningCommandswithsystem()orpassthru().Working with Images: Understanding the Image-Creation
Process, Necessary Modificationsto PHP, Drawing a New Image, Getting Fancy with Pie Charts, Modifying Existing
Images,ImageCreation from UserInput. Unit-5: (10hours) Interacting with MySQL using PHP: MySQL Versus MySQLi
Functions, Connecting toMySQL with PHP, Working with MySQL Data.
Page 1 of 91
, STUDY MATERIAL FOR
IIIB.SC (CS)PHP & MYSQL
Table of Contents
Unit I
What is PHP?, History, Features 3
PHP statements and comments 5
Variables 6
Constants 7
Operators 8
Conditional statements 9
Unit II
Array 14
Function 17
Unit III
Session 222
Cookie 24
PHP fscanf() Function 26
parse_ini_file() function Definition and Usage 27
Getting file information with stat 27
Get information about a file using stat(): 28
Fseek 28
Copying files with copy 28
Reading and writing binary files 29
PHP Read Single Character - fgetc() 30
Locking files 30
Unit IV
MySQL Database 332
Databases 322
Database Queries 322
Unit V
Database connectivity 33
Processing result sets of queries 35
Handling errors 39
Debugging and diagnostic functions 40
Validating user input through Database layer and Application layer 40
Understanding Requirements 85
Designing the Database 86
Page 2 of
, STUDY MATERIAL FOR
IIIB.SC (CS)PHP & MYSQL
What is PHP? UNIT PHP
PHP is an recursive acronym for "PHP: Hypertext Preprocessor"
PHP is a widely-used, open source (free to download, use, modify and rerelease)
scripting language
PHP scripts are executed on the server. – server side scripting language
PHP History
⮚ PHP was developed by Rasmus Lerdorf for monitoring his online resume in 1995. It
slowly became popular. This first version PHP/F1 has some basic functions.
⮚ PHP/F1 2.0 was released and was quickly replaced by PHP 3.0 in 1997
⮚ PHP 3.0 was interesting. It was developed by and Andi Gutmans and Zeev suraski. It
includes support for wider range of data bases (Oracle and My SQL). This version had
greater portability. It was used by thousands of web servers.
⮚ PHP 4.0 was released in 2003. It used a new engine and provided better performance,
greater reliability and scalability and support for web servers other than Apache. It also
supports OOP features and built-in session management.
⮚ PHP 5.0 offers a complete object oriented program models. It also includes better
exception handling, a more consistent XML tool kit, improved My SQL support and a
better memory manager. PHP 5.0 was the best in the languages 10 year history. A
survey was conducted by net craft in April 2004. It showed that PHP was in use for over
15 million websites.
Features of PHP
PHP as a programming language for the web has many advantages than JSP, ASP and
VB.NET. Because of its simplicity and open source availability it is the widely used scripting
language for websites. The features of PHP that are listed below makes PHP the most
enjoyable language for the developer community.
Simplicity
Even a beginner can easily to learn PHP because it has
⮚ Clearly written manual
⮚ Consistent and logical syntax
⮚ It may take only two hours for a programmer to learn PHP and write scripts.
⮚ It has Kiss principle for (Keep it simple stupid) rapid application development.
⮚ It can also access c library and take advantage of that code.
Portability
The PHP scripts can be made to work on different platformsfrom PHP 3.0 This is
because PHP code is interpreted not compiled.The meaning of this portability is developer can
write code on windows and deploy on Unix with interpreter for PHP. PHP scripts can be run on
Microsoft windows, Unix, Mac OS and OS/2.
Page 3 of
, STUDY MATERIAL FOR
IIIB.SC (CS)PHP & MYSQL
Speed
PHP scripts run faster that most scripting languages like ASP, JSP and Perl. when PHP
was released it had new parsing engine which made it faster. PHP 5.0 was even faster through the
use of optimized memory manager and object handler.
Page 4 of