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

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

Jun 13, 2016 am 10:07 AM
mysql php generally personal free supply support plan hour substitute of

一般个人免费主页空间都不会提供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 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

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

How to fix mysql_native_password not loaded errors on MySQL 8.4 How to fix mysql_native_password not loaded errors on MySQL 8.4 Dec 09, 2024 am 11:42 AM

One of the major changes introduced in MySQL 8.4 (the latest LTS release as of 2024) is that the "MySQL Native Password" plugin is no longer enabled by default. Further, MySQL 9.0 removes this plugin completely. This change affects PHP and other app

How To Set Up Visual Studio Code (VS Code) for PHP Development How To Set Up Visual Studio Code (VS Code) for PHP Development Dec 20, 2024 am 11:31 AM

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

CakePHP Quick Guide CakePHP Quick Guide Sep 10, 2024 pm 05:27 PM

CakePHP is an open source MVC framework. It makes developing, deploying and maintaining applications much easier. CakePHP has a number of libraries to reduce the overload of most common tasks.

How do you parse and process HTML/XML in PHP? How do you parse and process HTML/XML in PHP? Feb 07, 2025 am 11:57 AM

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

CakePHP Useful Resources CakePHP Useful Resources Sep 10, 2024 pm 05:27 PM

The following resources contain additional information on CakePHP. Please use them to get more in-depth knowledge on this.

See all articles