为什么调用函数时必须把数据库连接文件放在函数体里面
像下面这个程序:
<?
header("Content-type: text/html; charset=gb2312");
$act=$_GET["act"];
if($act=="del"){ //删除记录
$id =$_GET["id"];
require('conn.php');
$conn->query("delete from lyb where id=$id");
fy();}
if($act=="list") { fy();}
function fy() {
require('conn.php');
$sql="select * from lyb order by ID desc";
//echo $sql;
$result=$conn->query($sql);}
<?
header("Content-type: text/html; charset=gb2312");
require('conn.php');
$act=$_GET["act"];
if($act=="del"){ //删除记录
$id =$_GET["id"];
$conn->query("delete from lyb where id=$id");
fy();}
if($act=="list") { fy();}
function fy() {
$sql="select * from lyb order by ID desc";
//echo $sql;
$result=$conn->query($sql);}