Alternative solution without mysql support

Source: Internet
Author: User

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

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.