There are two basic ways to store data: Save to a normal file, or save to a database.
Data write:
1. Open the file. If the file does not exist, you need to create it first.
2. Write the data to this file.
3. Close this file.
Data read out:
1. Open the file. If this file is not open, you should be aware of this and launch it correctly.
2. Read the data from the file.
3. Close this file.
Select File Mode:
When opening a file, there are three options.
1. Open the file for read-only, write-only, or read and write.
2, if you want to write a file, you may want to overwrite the existing file content, or just append the new data to the end of the not seen. If the file already exists, you can also terminate the execution of the program instead of overwriting the file.
3. If you want to write a file on a system that distinguishes between a two-level mode and a plain text method, you must also specify the method to use.
The function fopen () supports the combination of the above three methods.
Depending on the server settings, the document root can be obtained in the following three ways:
$_server[' Document_root ']
$DOCUMENT _root
$HTTP _server_vars[' Document_root ']
For form data, the first style is the preferred one.
Open File fopen (path,mode)
Write file: fwrite ($fp, &outputstring)
Closing files: fclose ($FP)
File mode of the fopen () function
R Read-only mode-open the file and start reading from the file header
r+ read-write mode-open the file and read and write from the file header
W Write-only mode-open the file and start reading from the file header. If the file already exists, the contents of all files are deleted. If the file does not exist, the function creates the file.
X write the file with caution, and start writing from the file header. If the file already exists, the file will not be opened, the fopen () function will return false, and PHP will produce a warning.
x+ carefully write read/write mode to open the file, start writing from the file header. If the file already exists, the file will not be opened, the fopen () function will return false, and PHP will produce a warning.
A append Append mode--Open the file, if the file already has content, will be appended from the end of the file (write), if the file does not exist, the function will create this file
A + append Append mode--Open the file, if the file already has content, will be appended from the end of the file (write), if the file does not exist, the function will create this file
b binary Binary mode--for connecting to other modes. If the file system can differentiate between binary and text files, you may use it. Maximum portability can be achieved. Binary mode is the default mode.
The T text is used in conjunction with other modes. This mode is just the next option for Windows systems.
Open file in read-only mode: fopen ()
Know when to finish reading files: feof ()
Reads one row of data at a time: fgets (), FGETSS (), and Fgetcsv ()
Read the entire file: ReadFile (), Fpassthru (), and file ()
The first way is ReadFile (). ReadFile ($path); calling the ReadFile () function will open the file and output the contents of the file to standard output before closing the file.
The second way is Fpassthru (). To use this function, you must first open the file with fopen (). The file pointer is then passed as a parameter to Fpassthru () so that the file content pointed to by the file pointer is sent to the standard output. Then close the file again. If the read operation succeeds, the function returns True, otherwise false is returned.
The third function that reads the entire file is file (). It's the same as ReadFile. However, it sends the results to an array.
$filearray = file ($path);
The fourth option is to use the file_get_contents () function. This function is the same as ReadFile (), but the function returns the contents of the file as a string instead of echoing the contents of the file to the browser.
Read one character: Fgetc ()
while (!feof ($fp)) { $char = fgetc ($fp); if (!feof ($fp)) { echo ($char = = "\ n"? ") <br/> ": $char);} }
Read any length: Fread ()
The last way to read a file is to use the fread () function to read bytes of any length from the file.
To see if a file exists: File_exists ()
Determine file Size: FileSize ()
Delete a file: Unlink () (no function named Delete in PHP)
Locating in Files: Rewind (), fseek (), and Ftell ()
The rewind () function resets the pointer to the beginning of the file.
The Ftell () function can report the position of a file pointer in a file in bytes.
Call the Fseek () function to move the file pointer fp from the whence position to offset bytes.
The rewind () function is equivalent to calling a fseek () function with a 0 offset.
Lock the file:
To prevent multiple methods from manipulating one file at a time, you can use the file lock method.
File locking is implemented through the flock () function.
If you intend to use the flock () function, you must add it to all scripts that use the file;
Operation value of Flock ()
LOCK_SH read operation lock. This means that files can be shared and other people can read the file
LOCK_EX write Operation Lock. This is mutually exclusive. The file cannot be shared.
Lock_un Releasing existing locks
LOCK_NB prevent blocking on request locking
Database management System
RDBMS provides faster data access than regular files.
An RDBMS makes it easy to find and retrieve collections of data that meet certain criteria.
The RDBMS has built-in mechanisms for handling concurrent access.
The RDBMS can access the data randomly.
The RDBNS has a built-in permission system.
vieworders.php
<?php$document_root = $_server["Document_root"];? >
proccessorder.php
<?php$tireqty = $_post[' $tireqty ']; $oilqty = $_post[' $oilqty ']; $sparkqty = $_post[' $sparkqty ']; $address = $_post[' Address ']; $DOCUMENT _root = $_server[' document_root '); $date = Date (' h:i, JS F Y ');? >