有两个很基础的问题,困扰许久。
平台,PHP+MYSQL:
1. 都说mysql_query使用之后,要养成好习惯,断开数据库连接。但是像下面这种,一个页面重复@mysql_select_db一个数据表,断开后就连不上了。是否有必要每次都mysql_close?如果是,如何正确书写?
2. 一个页面include另一个页面,2个页面都有数据库操作,2个页面都需要 include  config.php 吗?好像main.php
不写,会报错,连接不上数据库。config.php<?php 
$handle_db1 = @mysql_connect("localhost","root","root") or die("can not connect Mysql Server");
$handle_db2 = @mysql_connect("1286734","root","root") or die("can not connect Mysql Server");
$handle_db3 = @mysql_connect("localhost","root","root") or die("can not connect Mysql Server");
$handle_db4 = @mysql_connect("1286734","root","root") or die("can not connect Mysql Server");
@mysql_select_db("content",$handle_db1);
@mysql_select_db("text",$handle_db2);
@mysql_select_db("usertable",$handle_db3);
@mysql_select_db("content",$handle_db4); 
?>index.php<?php include_once ('config.php'); ?>
<?php
@mysql_select_db("usertable",$handle_db3);
$result = @mysql_query("SELECT name FROM user order by id desc  LIMIT 0,5");
while ($row = @mysql_fetch_array($result))
{
?>                                     
<h5><?php echo $row['name']; ?></h5>
<?php
}
@mysql_close($handle_db3);
?>
<?php
@mysql_select_db("usertable",$handle_db3);
$result = @mysql_query("SELECT name FROM user order by id desc  LIMIT 10,5");
while ($row = @mysql_fetch_array($result))
{
?>                                     
<h5><?php echo $row['name']; ?></h5>
<?php
}
@mysql_close($handle_db3);
?>
<?php
@mysql_select_db("usertable",$handle_db3);
$result = @mysql_query("SELECT name FROM user order by id desc  LIMIT 15,5");
while ($row = @mysql_fetch_array($result))
{
?>                                     
<h5><?php echo $row['name']; ?></h5>
<?php
}
@mysql_close($handle_db3);
?>
<?php include(php/main.php); ?>main.php<?php include_once ('../config.php'); ?>
<?php
@mysql_select_db("text",$handle_db2);
$result = @mysql_query("SELECT * FROM mytext where date='2010.10' desc  LIMIT 15,5");
while ($row = @mysql_fetch_array($result))
{
?>                                     
<div class="details">date: <?php echo $row['date']; ?><br />
         title: <?php echo $row['title']; ?></div>
<?php
}
@mysql_close($handle_db2);
?>