再问:好像mysql_connect链接结束后是自动关闭的,为什么还要用close去关闭呢???头好大呀

解决方案 »

  1.   

    书上写的太罗嗦了!你自己如何看呢?
    mysql_connect and mysql_pconnect
    大家都是觉得那个好用就用那个,没有那么多的规矩的!
      

  2.   

    mysql_pconnect() acts very much like mysql_connect() with two major differences. First, when connecting, the function would first try to find a (persistent) link that's already open with the same host, username and password. If one is found, an identifier for it will be returned instead of opening a new connection. Second, the connection to the SQL server will not be closed when the execution of the script ends. Instead, the link will remain open for future use (mysql_close() will not close links established by mysql_pconnect()). --------------------------------------------------------------
    以上只是参考。楼上说的对,只要达到效率的要求,用哪个无所谓。看样子,mysql_connect和mysql_pconnect的效率差别不会很大
      

  3.   

    一般都是用mysql_connect()来调用,然后再一个页面里用完了马上关闭(close)
    这是一个很好的编程作风,因为如果一直保持连接是会占用系统资源的。而在一个页面里面,并不是所有的代码都要用到数据库操作的,所以应该在对数据库的操作结束的时候就close
    mysql_close():
    本函式关闭与 MySQL 资料库伺服器的连线。若无指定参数 link_identifier 则会关闭最后的一笔连线。用 mysql_pconnect() 连线则无法使用本函式关闭。实际上本函式不是一定需要的,当 PHP 整页程式结束后(注意,是整个页面执行结束,而不是数据库操作结束,所以有必要调用mysql_close()来关闭),将会自动关闭与资料库的非永久性 (non-persistent) 连线。成功传回 true、失败传回 false 值。
    mysql_connect():
    本函式建立与 MySQL 伺服器的连线。其中所有的参数都可省略。当使用本函式却不加任何参数时,参数 hostname 的内定值为 localhost、参数 username 的内定值为 PHP 执行行程的拥有者、参数 password 则为空字串 (即没有密码)。而参数 hostname 后面可以加冒号与埠号,代表使用那个埠与 MySQL 连接。当然在使用资料库时,早点使用 mysql_close() 将连线关掉可以节省资源。
    mysql_pconnect():
    本函式和 mysql_connect() 雷同。不同的地方在于使用本函式开启资料库时,程式会先寻找是否曾经执行过本函式,若执行过则传回先前执行的 ID。另一个不同的地方是本函式无法使用 mysql_close() 关闭资料库。
      

  4.   

    还有没有 我觉得还没有完 
    因为我用mysql_connect比 mysql_pconnect明显要慢
      

  5.   

    我也用mysql_connect
    据说是一直连着数据库的?