PHP does not have MySQL support when the alternative _php tutorial

Source: Internet
Author: User
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 ...

  • 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.