General Personal Free home page space will not provide MySQL support, is also very harsh, so looking for a good alternative is very important oh!
PHP file processing function is very powerful, so you can use the file access to replace!
(To know that when there is no database, everything is organized by the file Oh!) Oh! ), where the data items are segmented with extraordinary symbols, I use "| |" to easily read a single record through the Explode () function!
In fact, the idea of the database here can still be used! Like the index of the database!
So you have to make an index file first! (That's not true.)
Let's take the message book:
The main documents are:
Index.database
The structure is as follows:
Name of the person who left the message | | Message Person Sex | | Message Time | | Message Content Storage Location | | Feiyn (This is easy to read when the ' n ' is annoyed!
Each row of storage can be conveniently read by the PHP fgets () function, or the file () function reads each line to an array
Lock (also file implementation) is required to prevent multiple people from writing conflicts with data
Here is the write code
The following parameters must be passed in:
Name of the person who left the message $name
Message person Sex $sex
Message Time $time
Message Content Storage location $savePosite
$indexFile = "Index.database";
$indexFileLock = $indexFile. " Lock ";
$message = $name. "| |". $sex. "| |". $time. "| |". $savePosite. "| | feiy| | "; /This is the record to write
while (File_exists ($indexFileLock)) $temp; Detect if lock has been added
Fclose (fopen ($indexFileLock, "w")); If not, enter and lock to avoid the same access violation
$FP =fopen ($indexFile, "a");
Fputs ($message, strlen ($message));
Fclose ($FP);
Unlink ($indexFileLock);//unlock
?>
Read code
$indexFile = "Index.database";
$indexFileLock = $indexFile. " Lock ";
while (File_exists ($indexFileLock)) $temp; Detect if lock has been added
Fclose (fopen ($indexFileLock, "w")); If not, enter and lock to avoid the same access violation
$ary =file ($indexFile);
Unlink ($indexfileLock);//unlock
for ($i =0; $i
$tempAry =explode ("| |", $ary [$i]);
Echo ("Name:". $tempAry [0]);
Echo ("Sex:". $tempAry [1]);
Echo ("Sex:". $tempAry [2]);
Echo ("Saveposite:", $tempAry [3]);//can read message content from this address
}
?>
http://www.bkjia.com/PHPjc/630942.html www.bkjia.com true http://www.bkjia.com/PHPjc/630942.html techarticle General Personal Free home page space will not provide MySQL support, is also very harsh, so looking for a good alternative is very important oh! PHP file processing function is very powerful, so ...