In other words, I am an expert, and I am eager to take advantage of the ysql support in the morning, that is, it is very demanding to provide, so it is very important to find a good alternative!
PHP file processing is very powerful, so it can be replaced by file access! (When there is no database, all files are organized! Haha !), The data items are separated by special symbols. I use "|" to read a single record through the explode () function!
In fact, the Database concept can still be used here! Like the database index! Therefore, you must create an index file first! (This is not true)
Let's talk about it in the message book:
The main file is index. database.
Its structure is as follows:
Name of the contact person | Gender of the contact person | message time | location of the message content | feiyn!
Each row can be easily read using the fgets () function of PHP, or the file () function to read each row to the array.
To prevent data conflicts between multiple users, you need to apply a lock (also implemented using files)
Write the following code:
$ #@ 60 ;? Php
// The following parameters must be input:
// Name of the contact $ name
// Gender of the message recipient $ sex
// Message time $ time
// Location where the message content is stored $ savePosite
$ IndexFile = "index. database ";
$ IndexFileLock = $ indexFile. "Lock ";
$ Message = $ name. "| ". $ sex. "| ". $ time. "| ". $ savePosite. "| feiy |"; // This is the record to be written.
While (file_exists ($ indexFileLock) $ temp ++; // checks whether the lock has been applied.
Fclose (fopen ($ indexFileLock, "w"); // if not, enter and lock to avoid access conflicts.
$ Fp = fopen ($ indexFile, "");
Fputs ($ message, strlen ($ message ));
Fclose ($ fp );
Unlink ($ indexFileLock); // unlock
? $ #@ 62;
Read code:
$ #@ 60 ;? Php
$ IndexFile = "index. database ";
$ IndexFileLock = $ indexFile. "Lock ";
While (file_exists ($ indexFileLock) $ temp ++; // checks whether the lock has been applied.
Fclose (fopen ($ indexFileLock, "w"); // if not, enter and lock to avoid access conflicts.
$ Ary = file ($ indexFile );
Unlink ($ indexfileLock); // unlock
For ($ I = 0; $ I $ # @ 60; sizeof ($ ary); $ I ++ ){
$ TempAry = explode ("|", $ ary [$ I]);
Echo ("name:". $ tempAry [0]);
Echo ("sex:". $ tempAry [1]);
Echo ("sex:". $ tempAry [2]);
Echo ("savePosite:", $ tempAry [3]); // you can read the message content from this address.
}
? $ #@ 62;
Which of the following methods can be used? Solutions for commonly used Web pages, such as chat rooms, BBS forums, and bookmarks