define function,reading file into array,reading and writig binary files,
deleting files with unlink,locking files,file handling operations,database,php supported database,accessing the database in php,
Z Score,T Score, Percential Rank and Box Plot Graph
File handling
1.
2. PAPER NAME : PROGRAMMING IN PHP
STAFF NAME : MS.V.SHANTHI M.SC,M.PHIL,M,TECH,PGDCA.
CLASS : III BCA
SEMESTER : VI
3. FILE HANDLING:
This chapter discusses file handling using PHP. Storing data
on the server is especially powerful in web applications,
because it allows you to make data “persist”-that is, stick
around between page accesses. Blogs, guest books, feedback
pages- all are possible when you work with files on the server.
There’s a lot of PHP technology coming up in this chapter,
starting with opening files .
4. EXAMPLE:
<html>
<head>
<title>
Reading from a file
</title>
<body>
<h1>
Reading from a file
</h1>
<?php
$handle= fopen(“file.txt”, “r”);
while(!foef($handle)){
.
.
.
}
?>
</body>
</html>
5. READING A FILE INTO AN ARRAY
WITH FILE:
You can use the file function to read a file into an array all at
ones; each line becomes an element in the array. Here’s how to
use the file function;
file(file name [, use _ include_ path[,context]])
6. READING AND WRITING BINARY
FILES:
You can write binary data with f1write, and read it with fread,
but it takes a little work. You can pack binary data into strings
using the pack function, and unpack binary data using the
unpack function.
Example, phpwritebinary.php, that writes the number 512 to a file
in binary(not string)format. If starts by opening the file for
binary writing like this;
<?php
$number=512;
$handle= fopen(“data.dat”, “wb”);
.
.
7. DELETING FILES WITH UNLINK:
Want to delete a file? You can do that with the unlink function:
unlink(filename[,context])
Here, filename is the name of the file, and context is an
optional context. This function returns TRUE if the file was
deleted, FALSE otherwise.
You can find an example in phpunlink.php. If the code is
successful in deleting copy.txt, it says so:
<?php
if(unlink(“copy.txt”)){
echo “Deleted the file.”;
}
.
.
8. LOCKING FILES:
In a multiuser environment, such as web server, multiple users
may be accessing your scripts at the same time,which means
multiple copies of the same script can operate at the same time.
If your script(s) accesses files, there may be a conflict as to
scripts, or to copies of the same script, tries to write to the same
file at the same time. To fix that, use the file locking function.
Here, handle is the handle of the file you want to lock, and
operation is one of these:
To attain a shared lock(reader), set operation to LOCK_SH.
To attain an exclusive lock(writer), set operation to LOCK_EX.
To release a lock, set operation to LOCK_UN.
9. FILE HANDLING OPERATIONS:
File handling starts with creating a file, reading its content,
writing into a file to conjoin data into an existing file and
finally closing the file. PHP provides predefined functions for
all these operations.
1. Create a file : fopen()
2. Open a file : fopen()
3. Read a file : fread()
4. Write to a file : fwrite()
5. Append to a file: fwrite()
6. Close a file : fclose()
7. Delete a file : unlink()
10. DATABASE:
What is a database?
We’ll take a lock at what makes a database here briefly(and if
you are already familiar with databases, tables, and so on , you
can naturally skip this intro).
Databases organise data for easy access and use by
programs.the most popular database construct is the table and
we’ll take a lock at tables here. Say, foe example that you’re
teaching PHP to a class of students and want to keep track of
their scores. You might create a table with two columns, Name
and Grade:
12. Accessing the database in PHP:
When you install PHP, you can select from a number of
protraction. To install support for My SQL, click the
extension node in the installer to open that node and select the
My SQL node to install that extension. Your PHP installation
may have already been installed with My SQL support most
installation on web servers are.
13. The My SQL support in PHP consists of a number of
functions you can call to interact with My SQL, and here they
are:
My sql affected rows Get the number of rows affected by the
previous MySQL operation.
My sql change user Change the logged-in user.
My sql client encoding Return the name of the current
character set.
My sql close Close a MySQL connection.
My sql connect Open a connection to a MySQL Server.
My sql create db Create a MySQL database.
My sql data seek Seek data in the database.
My sql db name Get the name of the database.
My sql db query Send a My SQL query.