PHP does not have MySQL support when the alternative _php Foundation

Source: Internet
Author: User
Tags explode
The General Personal free homepage space will not provide MySQL support, is to provide also very harsh, so looking for a good alternative is very important oh!
PHP's file processing is very powerful, so you can use file access to replace it!
(To know when there is no database, everything is organized with files!) Oh! , where the data items are separated by special symbols, I am using "| |" to facilitate the reading of a single record through the Explode () function!
In fact, the idea of the database here is still available! Like the index of the database!
So you have to do an index file first! (That's not true)
Let's leave a message for this:
The main documents are:
Index.database
The structure is as follows:
Message Person Name | | Message Person Sex | | Message Time | | Message Content Storage Location | | Feiyn (This is easy to read when the ' n ' Jerky!)
Each store row can be easily read through the PHP fgets () function, or the file () function reads each row to the array
In order to prevent multiple people from writing to the data conflict, it is also necessary to lock (also implemented by file)
Here is the write code
<?php
The following parameters must be passed in:
Message person name $name
Message Person Gender $sex
Message Time $time
Message Content 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 no, enter and lock to avoid the same access violation
$FP =fopen ($indexFile, "a");
Fputs ($message, strlen ($message));
Fclose ($FP);
Unlink ($indexFileLock);//unlock
?>
Reading code
<?php
$indexFile = "Index.database";
$indexFileLock = $indexFile. " Lock ";
while (File_exists ($indexFileLock)) $temp + +; Detect if lock has been added
Fclose (fopen ($indexFileLock, "w")); If no, enter and lock to avoid the same access violation
$ary =file ($indexFile);
Unlink ($indexfileLock);//unlock
for ($i =0; $i <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 from this address
}
?>

Through the above can easily solve the common use of web pages, such as chat rooms, BBS forums, bookmarks and so on
If the prawn has a better solution, please enlighten me! Thank you!
My homepage: feiyschool.51.net
qq:23072155
Email:feiyhy@sina.com

"This article copyright belongs to the author Feiy and Osso Nets jointly owned, if need to reprint, please specify the author and source"


Related Article

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.