PHP alternative when there is no mysql support_PHP tutorial

WBOY
Release: 2016-07-21 16:00:36
Original
739 people have browsed it

Generally, personal free homepage spaces do not provide MySQL support, and even if they do, it is very demanding, 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 have to 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 through the explode() function. Single record!
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
The structure is as follows:
Name of the messager||Gender of the messager| |Message time||Message content storage location||feiyn (this is convenient for reading when being annoyed by 'n'!
Each message is stored in one line and can be easily read through PHP's fgets() function, or The file() 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
< ?php
//The following parameters must be passed in:
//Name of the messager $name
//Gender of the messager $sex
//Time of message $time
//Storage of message content 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++; //Check whether it is locked
fclose(fopen($indexFileLock,"w")); //If not, enter and lock to avoid the same access conflict
$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++; //Check whether it is locked
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]);//The message content can be read from this address
}
?>

The above can easily solve common web page applications, such as Chat rooms, BBS forums, bookmarks, etc.
If that prawn has a better solution, please let me know! Thanks!
My homepage: feiyschool.51.net
QQ:23072155
email:feiyhy@sina.com

[The copyright of this article is jointly owned by the author feiy and Aosuo.com, if you need to reprint it , please indicate the author and source]


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/317029.htmlTechArticleGenerally, personal free homepage spaces will not provide mysql support, even if it is provided, it is very demanding, so it is better to find a good one Alternatives are important! PHP's file processing function is very powerful, so...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template