开发者

PHP error closing a mysql connection

开发者 https://www.devze.com 2023-02-06 13:07 出处:网络
I\'m using a very simple function: function closeConn(){ mysql_close($conn); } $conn is the connection variable - it connects ok but i get this error if i try and call it:

I'm using a very simple function:

function closeConn(){
    mysql_close($conn);
}

$conn is the connection variable - it connects ok but i get this error if i try and call it:

Warning: mysql_close() expe开发者_如何转开发cts parameter 1 to be resource, null given in

What is the reason for this?


The reason is, $conn variable is empty.

Either pass it as an argument to your function:

function closeConn($conn){
    mysql_close($conn);
}

closeConn($conn);

or just don't use it at all and let PHP decide which connection to close (by default, tha last one that was opened)

function closeConn(){
    mysql_close();
}

or just don't close the connection at all. PHP does it for you anyway, when the script's execution ends.

0

精彩评论

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