Professional Documents
Culture Documents
Topics
• Background and History of PHP
• Installation
• Comments in PHP
• Variables
• Conditions
• Loops
• Functions
• File Handling
• Database Handling (MySQL, MSSQL, ODBC)
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 */
Sample PHP
<html>
<body>
<?php echo “hello”; ?>
</html>
• Example
– mysql_close($con);
– mssql_close($con);
ODBC Data handling
• Connect to a data source
– odbc_connect(dsn,uname,pwd);
– DSN – Data Source Name
– Go to Control Panel -> Administrative Tools ->
Datasources (ODBC)
– Click on ODBC and select System DSN tab.
– Click Add and choose Access Database
(mdb) and click Finish
– In the dialog that appears, give DSN Name
and Description
ODBC Data handling Contd..
– Click on Select under Database section
– Choose a mdb (access database file) and give
OK
• $conn=odbc_connect('nwind','','');
– Here nwind is the DSN that we have created in
our system to access a database
– We have not given any user name or
password during DSN creation
– So those fields are left empty.
Selecting rows from a table
• $rs = odbc_exec($conn,$sql);
– $conn – connection string
– $sql – SQL query to select rows from table
– $rs is the result set of the query execution
• odbc_fetch_row($rs)
– This command fetches row by row from the result set
• $cid = odbc_result($rs,"CustomerID");
– This command fetches value for the column
CustomerID from the current row and stores it in the
variable $cid.
Closing Connection
• odbc_close(connection)
– This function closes the connection obtained
and releases the same to the connection pool
• odbc_close($conn);
– The connection defined by $conn is released
and no query can be executed using this
connection variable hence forth.