开发者

Automatic db connection close in php?

I have following in my config.php file for one of my web app.

//db settings
    $host = 'localhost'; //database location
    $user = 'example'; //database username开发者_如何学运维
    $pass = 'example12'; //database password
    $db_name = 'example'; //database name

//create db connection
    $link = mysql_connect($host, $user, $pass);
    mysql_select_db($db_name);

//sets encoding to utf8
    mysql_query("SET NAMES utf8");

I am including config.php in all pages of my application at top (1st line of code).

I want to know that will PHP/MYSQL maintain connection open and close automatically or I need to explicitly call them. Connection is opening by itself, as I am doing all db based tasks properly. But not closing connection anywhere, this is a high traffic website.

Please correct me if I am wrong anywhere.

Thanks!


The connection will close automatically upon termination of the script.

The notes on mysql_connect() state that:

The link to the server will be closed as soon as the execution of the script ends, unless it's closed earlier by explicitly calling mysql_close().

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜