Php: an alternative when mysql is not supported _ PHP Tutorial

Source: Internet
Author: User
Php is not an alternative to mysql support. Generally, no mysql support is provided for personal free homepage space, that is, it is also very demanding, so it is important to find a good alternative! The file processing function of PHP is very powerful, so mysql support is not provided for personal free homepage space, that is, it is also very demanding, 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 files are:
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)
The following code is written:
// 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
?>
Read code
$ 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 $ 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.
}
?>

Through the above, you can easily solve commonly used Web pages, such as chat rooms, BBS forums, bookmarks, and so on.
If that prawn has a better solution, please enlighten me! Thank you!
My Homepage: feiyschool.51.net
QQ: 23072155
Email: feiyhy@sina.com

[The copyright of this article is shared by the authors feiy and osuo. if you need to reprint it, please indicate the author and its source]


Success! PHP file processing is very powerful, so...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.