search
Homephp教程php手册PHP之没有MySQL支持时的替代方案

PHP之没有MySQL支持时的替代方案

Jun 13, 2016 am 10:07 AM
mysqlphpgenerallypersonalfreesupplysupportplanhoursubstituteof

一般个人免费主页空间都不会提供mysql支持,就是提供也很苛刻,所以寻找也个良好的替代方案很重要哦!
PHP的文件处理功能很强大,所以可以用文件的存取来代替来!
(要知道没有数据库的时候,什么都是用文件组织的哦!呵呵!),其中个数据项用非凡符号分割,我采用的是“||”,方便通过explode()函数读取单个记录!
其实这里数据库的思想还是可以用到的!象数据库的索引!
所以必须先做个索引文件!(这样说也并不正确)
就以留言本来说吧:
主要文件是:
index.database
其结构如下:
留言人姓名||留言人性别||留言时间||留言内容存放位置||feiyn(这项是方便读取时的被‘n’干恼的!
每条存储一行可以方便的通过PHP的fgets()函数读取,或者file()函数读取每行到数组
为了防止多人同是对数据的写入冲突,故还需要加锁(也用文件实现)
以下是写入代码
//必须传入以下参量:
//留言人姓名 $name
//留言人性别 $sex
//留言时间 $time
//留言内容存放位置 $savePosite
$indexFile="index.database";
$indexFileLock=$indexFile."Lock";
$message=$name."||".$sex."||".$time."||".$savePosite."||feiy||";//这就是要写入的记录
while(file_exists($indexFileLock)) $temp ; //检测是否已加锁
fclose(fopen($indexFileLock,"w")); //如没有则进入并加锁避免同是访问冲突
$fp=fopen($indexFile,"a");
fputs($message,strlen($message));
fclose($fp);
unlink($indexFileLock);//解锁
?>
读取代码
$indexFile="index.database";
$indexFileLock=$indexFile."Lock";
while(file_exists($indexFileLock)) $temp ; //检测是否已加锁
fclose(fopen($indexFileLock,"w")); //如没有则进入并加锁避免同是访问冲突
$ary=file($indexFile);
unlink($indexfileLock);//解锁
for($i=0;$i $tempAry=explode("||",$ary[$i]);
echo("name:".$tempAry[0]);
echo("sex:".$tempAry[1]);
echo("sex:".$tempAry[2]);
echo("savePosite:",$tempAry[3]);//可以从该地址读取留言内容
}
?>

Statement
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.