The old mysql_close() function closed a connection created by the removed original MySQL extension. Current applications use PDO or MySQLi instead.
<?php
// Historical only: removed from PHP 7+
mysql_close($link);
?>
A normal PDO connection is released when its object is destroyed, typically at script end. You can release it earlier by removing the reference:
<?php
$dbo = null;
?>
<?php
$connection->close();
?>
<?php
$dbo = new PDO(
'mysql:host=localhost;dbname=sql_tutorial;charset=utf8mb4',
'userid',
'password',
[PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION]
);
$total = $dbo->query('SELECT COUNT(*) FROM student')->fetchColumn();
echo 'Total records in Student table = ' . $total;
$dbo = null;
?>
Explicitly closing a normal connection is optional when the script is about to end. See PHP/MySQL connections and executing queries.
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.