当前位置:文档之家› Php中关闭数据库链接的时候注意

Php中关闭数据库链接的时候注意

Php中关闭数据库链接的时候注意
没有错
<?php
require_once ("../config.php");
require_once (_CMSDIR . "/class/admin.class.php");
require_once (_CMSDIR . "/class/systemType.class.php");
require_once (_CMSDIR . "/class/member.class.php");
$admin = new admin ( );
if ($_SERVER ['REQUEST_METHOD'] == "POST") {
//判断会员id是不是存在
$member = new member ( );
$member->search ( "id=" . $_POST ["mId"] );
if ($member->countnum < 1) {
$member->close();
echo "<script>history.back(-1);alert('用户表中没有此id,请重新输入!');</script>";
exit ();
}
//判断用户名是不是已经被注册了
$thisResult = $admin->getCount ( "aName='" . $_POST ["aName"] . "'" );
if ($thisResult > 0) {
echo "<script>history.back(-1);alert('此用户名已经被注册!');</script>";
$admin->close ();
exit ();
}
//添加记录
$admin->add ();
$member->close();
$admin->close ();
turntopage ( "admin_add.php", "您已经成功添加一条记录!",3);
}
//从用户权限组里查找全部数据
$admintype = new systemtype ( );
$types = $admintype->getall ( " 1=1" );
include ("templets/admin_add.html");
$admin->close ();
$admintype->close ();
?>
下面的就有错了
<?php
require_once ("../config.php");
require_once (_CMSDIR . "/class/admin.class.php");
require_once (_CMSDIR . "/class/systemType.class.php");
require_once (_CMSDIR . "/class/member.class.php");
$admin = new admin ( );
if ($_SERVER ['REQUEST_METHOD'] == "POST") {
//判断会员id是不是存在
$member = new member ( );
$member->search ( "id=" . $_POST ["mId"] );
$member->close ();
if ($member->countnum < 1) {
echo "<script>history.back(-1);alert('用户表中没有此id,请重新输入!');</script>";
exit ();
}
//判断用户名是不是已经被注册了
$thisResult = $admin->getCount ( "aName='" . $_POST ["aName"] . "'" );
if ($thisResult > 0) {
echo "<script>history.back(-1);alert('此用户名已经被注册!');</script>";
$admin->close ();
exit ();
}
//添加记录
$admin->add ();
$admin->close ();
turntopage ( "admin_add.php", "您已经成功添加一条记录!", 300 );
}
//从用户权限组里查找全部数据
$admintype = new systemtype ( );
$types = $admintype->getall ( " 1=1" );
include ("templets/admin_add.html");
$admin->close ();
$admintype->close ();
?>
总结:上面的区别是一个数据关闭的较早一个较晚,所以关闭的时候一定要注意实时的关闭,和适时的关闭。

相关主题