php操作ACCESS(读写改) 实例教程
来源:
互联网
日期:2012-12-24
Tc711Com提示:今天给大家分享:php操作ACCESS(读写改)实例教程 ,亲测可用. | php操作ACCESS(读写改)
Conn.php
---------------------------------------------
<?php
/*数据库路径,请自己修改,否则可能运行不正常*/
$conn = @new COM("ADODB.Connection") or die ("ADO连接失败!");
$connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" . realpath("include/#mydb.mdb");
$conn->Open($connstr);
//创建记录集查询
?>
Add.php
<?php
$name=$_POST['user_name'];
$content=$_POST['user_post'];
if ($name<>"" and $content<>"")
{
if($name="admin" or $content="admin")
{
echo "<script language='javascript'>alert('你要干什么!');location='index.php';</script>";
}
include_once("include/conn.php");
$rs = $conn->Execute("insert into contents (name,content) values ('$name','$content')");
header("location:index.php");
}
else
echo "<script language='javascript'>alert('字段不能有空!');location='index.php';</script>";
?>
Del.php
<?
session_start();
if($_SESSION['admin']=="OK")
{
include_once("include/conn.php");
$sql="delete from contents where id=".$_GET['id'];
$rs = $conn->Execute($sql);
header("location:admin_index.php");
}
?>
Show.php
<?
session_start();
if($_SESSION['admin']=="OK")
{
include_once("include/conn.php");
$sql="select * from contents where id=".$_GET['id']; /*$_GET['id']是传递过来的参数 */
$rs = $conn->Execute($sql);
$name=$rs->Fields['name']->Value;
$content=$rs->Fields['content']->Value;
$id=$rs->Fields['id']->Value;
?>
<form action="modify_save.php" method="post" name="name1">
ID :<?=$id?><input type="hidden" name="id" value=<?=$id?> >
姓名:<?=$name?><br>
留言:<textarea name="post_contents" rows="10" cols="50"><?=$content?></textarea>
<input type="submit" value="提交修改">
</form>
<?
}
$rs->Close();
$conn->Close();
$rs = null;
$conn = null;
?>
Edit.php
<?
session_start();
if($_SESSION['admin']=="OK")
{
include_once("include/conn.php");
$sql="update contents set content='".$_POST['post_contents']."' where id=".$_POST['id'];
$rs = $conn->Execute($sql);
}
header("location:admin_index.php");
?>
更多的php操作ACCESS(读写改) 实例教程请到论坛查看: http://BBS.TC711.COM
【 双击滚屏 】 【 评论 】 【 收藏 】 【 打印 】 【 关闭 】
来源:
互联网
日期:2012-12-24
|
|
|