Warning: mysql_close(): 5 is not a valid MySQL-Link resource

我寫的程式發生了上列訊息,在關閉 MySQL 連線時發生錯誤,趕快上網找了一下資料,

發現蠻多人會有這樣的問題,而解決方法是在 mysql_close() 前方加上@,讓程式發生錯

誤時不顯示出來,會這樣做的原因是 PHP 手冊對 mysql_close() 解說,基本上在使用

MySQL連線時,使用mysql_connect()時在執行完整個程式後如果不加上mysql_close()

,PHP 還是會幫你關閉連線,如果使用的是 mysql_pconnect() 方式,mysql_close()

他並不會幫你 close persistent links,所以我們不需要特定在意 MySQL 的連線會不會因

為發生這樣的異常而導致連線不被關閉,到程式結束後 PHP 會自動關閉連線。

(如果想知道出錯原因,可看一下這個網站)

 

PHP mysql_close() 說明:

mysql_close() closes the non-persistent connection to the MySQL server that's associated with the specified link identifier. If link_identifier isn't specified, the last opened link is used.

Using mysql_close() isn't usually necessary, as non-persistent open links are automatically closed at the end of the script's execution

Note: mysql_close() will not close persistent links created by mysql_pconnect()

參考:

http://php.net/manual/en/function.mysql-close.php

http://hi.baidu.com/webwlsong/blog/item/440a433b8e4112e914cecbee.html

arrow
arrow
    全站熱搜

    iammic 發表在 痞客邦 留言(0) 人氣()