您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php储存数据的方法

2024/4/17 23:54:34发布23次查看
php存储数据的方法(推荐学习:php视频教程)
存储数据有两种基本方法:保存到普通文件,或者保存到数据库中。当具有大量订单时,应该使用一个数据库管理系统。
 html代码如下:
<html>
<head>
<title>bob's auto parts</title>
</head>
<body>
<h1>bob's auto parts</h1>
<h2>order form</h2>
<form action="processorder.php" method="post">
<table border="0">
<tr bgcolor="#cccccc">
<td width="150">item</td>
<td width="15">quantity</td>
</tr>
<tr>
<td>tires</td>
<td align="left"><input type="text" name="tireqty" size="3" maxlength="3"/></td>
</tr>
<tr>
<td>oil</td>
<td align="left"><input type="text" name="oilqty" size="3" maxlength="3"/></td>
</tr>
<tr>
<td>spark plugs</td>
<td align="left"><input type="text" name="sparkqty" size="3" maxlength="3"/></td>
</tr>
<tr>
<td>shipping address</td>
<td align="center"><input type="text" name="address" size="40" maxlength="40"/></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" value="submit order"/></td>
</tr>
</table>
</form>
</body>
</html>

打开文件
fopen()函数可以打开一个文件。
$fp = fopen(“$document_root/orders.txt”,’w’);

由于我们为表单变量定义了一个简短名称,我们需要在脚本的开始处加上如下代码:
$document_root = $_server[‘document_root’];

可以通过如下3种方式得到文档根目录:
$_server[‘document_root’]$document_root$http_server_vars[‘document_root’]

fopen()有四个参数,其中第一个参数是路径。
第二个参数是文件模式。
第三个参数可选,如果要在include_path中搜索一个文件,就可以使用它。
第四个参数也可选,fopen()函数允许文件名称以协议名称开始并且在一个远程的位置打开文件。
也可以使用fopen()函数通过ftp、http或其他协议来打开文件。
注意,url中的域名不区分大小写,但是路径和文件名可能会区分大小写。
以上就是php储存数据的方法的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product