最好的习惯是有始有终做程序也一样打开连接后自然要关闭才好.
PHPLIB中最好还是用mysql_connect
template类不象数据库存储,在输出后没有必要销毁.
为了增加可读性你可以试着把复杂的语句分开写但为了简洁还是写成一句比较好.

解决方案 »

  1.   

    mysql_connect在页面结束后会自动关闭的
      

  2.   

    及时mysql_close有利于大量的并发访问。
      

  3.   

    phplib中的DB_Sql类中有没有负责关闭链接的函数?我指的是如何高效的使用DB_SQL,现在我这样使用:
    <?php
       /**************************************************************
       *  文件名: get_pwd2.php
       *  作  用: 
       *  时  间: 
       *  
       *  版  权: 
       *  作  者: 
       *
       ****************************************************************/  require ("db_mysql.inc");
      require ("template.inc");  $db = new DB_Sql();
      $template = new Template(".");  $db->connect();  $UserID = $_POST["UserID"];
      $db->query("SELECT tb_UserInfo.vcPasswd, tb_User_Question.vcQuestion FROM tb_UserInfo, tb_User_Question WHERE tb_UserInfo.vcUserID = '$UserID' AND  tb_User_Question.iQuestionID = tb_UserInfo.imQuestionID");  if(0 != $db->num_rows())  //存在这个用户
      {
        $db->next_record();
      
        
        $template->set_file("handle", "template/get_pwd2.ihtml");
        $template->set_var("Question", $db->f("vcQuestion"));
    $template->set_var("UserID", $UserID);
        $template->set_var("Message", "请输入您提示问题的答案!");
        $template->parse("out", "handle");
        $template->p(out);
      }
      else //不存在此用户返回到第一步
      {
       $template->set_file("handle", "template/get_pwd.ihtml");
       $template->set_var("Message", "对不起,你输入的用户名不存在,请重试!");
       $template->parse("out", "handle");
       $template->p(out);
      }
    ?>
    ================================
    这里没有对数据库对象$db的关闭,也没有对实例化的$template进行销毁,这样我总感觉到有问题,怎么解决,还请大家多多发言