简体   繁体   中英

PHP close MySQL connection

I have a file config.php

<?php

$dbhost = "*****";
$dbname = "*****";
$dbuser = "*****";
$dbpassword = "*****";

$connect = mysql_connect("$dbhost","$dbuser","$dbpassword");
mysql_select_db("$dbname",$connect);

mysql_query("SET NAMES 'utf-8'");
?>

And i have file insert.php with inserting form values into MySql. At the end of this file i am trying to close database connection with:

mysql_close($connection);

but it gives me error, please advise.

PS: I am very new to php so please don't blame.

试试这个代码

mysql_close($connect);

You are using mysqli_close($connect) instead of mysql_close($connect);

$connect = mysql_connect("$dbhost","$dbuser","$dbpassword");
mysql_close($connect);

I would suggest you to move your code to mysqli because mysql is not supported anymore in php7

You should use mysqli because mysql is not supported anymore in PHP latest version. and you are trying to close database connection with mysqli. use like this.

mysql_close($connect);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM