08-12-2012, 02:59 PM
PHP Programming
php.ppt (Size: 202.5 KB / Downloads: 46)
Background
Personal Home Page – C kind of scripts written in Perl language, by Rasmus Lerdorf in 1995.
He called the language as PHP/FI – Personal Home Page / Forms Interpreter.
1997 Version 2.0 was released
Then came 3.0, 4.0. They were called PHP simply
Recent version is PHP 5.2.3
Installation
Apache server need to be installed first
The config file for apache server will be present in the conf folder under the apache installed directory
Set the DocumentRoot to the path where the PHP files will be stored
Install PHP. Point apache conf directory when it asks so and select the appropriate web server.
Move the PHP.ini file to C:\WNDOWS directory
PHP Comments
All php files are saved with extension .php
The can be written in notepad or any text editor
Single line comment
// this is single line comment
Multi line comment
/*….
This is a multi line comment */
Variables
Variables start with a $ symbol
Variables can contain _ or numbers or alphabets
$ should be followed by _ or alphabet and not by a number
PHP is loosely typed language. There is no strict data typing
Variable can be assigned with any values
Functions and Parameters
PHP functions need to be defined with key word function
It can have zero or more values (parameters)
Functions may or may not return values
If a function need to return value, the last statement of the function should be return
return value;
Reading a file
Several methods are available
fread(filepointer,no of bytes to read)
fgetc(filepointer) – Reads character by character
fgets(filepointer) – Reads line by line
The read content can be stored in a variable
$data = fread($fp,10) – this reads 10 characters from file pointed by file pointer $fp and stores in $data
If we want to read characters till end, we need to use a loop with condition checking for End of File
MySQL and MSSQL Connection
mysql_connect(dbserver,userid,password)
mssql_connect(dbserver,userid,password)
These methods are used for connecting to MySQL and MSSQL server using a userid and password
$con = mysql_connect(‘localhost’,’root’,’root’);
This gets a connection to the local mysql server using the credentials root and root
If server cannot be connected, it will throw an error stating the problem
Note: Mysql and MSSQL can be accessed in identical way except for the preceeding mysql or mssql. So will use mysql henceforth.