∫If you want to support YSSQL, it is very demanding even if it is provided, so it is important to find a good alternative!
PHP’s file processing function is very powerful, so you can use file access instead! (You must know that when there is no database, everything is organized by files! Haha!). Each data item is separated by special symbols. I use "||" to facilitate reading a single record through the explode() function!
In fact, the idea of database can still be used here! Like a database index! So you must make an index file first! (It is not correct to say this)
Let’s take the guestbook as an example:
The main file is: index.database
Its structure is as follows:
Message person’s name | | Message person’s gender | | Message time ||The message content storage location||feiyn (this is convenient for reading when being annoyed by 'n'!
Each message stores one line and can be easily read through PHP's fgets() function, or file() The function reads each line into an array
In order to prevent conflicts between multiple people writing data at the same time, locking is also required (also implemented using files)
The following is the writing code:
$#@60 ;?php
//The following parameters must be passed in:
//Name of the messager$name
//Gender of the messager$sex
//Time of the message$time
//Content of the message Storage location $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++; //Detect whether it is locked
fclose(fopen($indexFileLock,"w")); //If not, enter and lock to avoid access conflicts
$fp=fopen($indexFile,"a");
fputs ($message,strlen($message));
fclose($fp);