connect_errno) { echo "Failed to connect to MySQL: " . $mysqli -> connect_error; exit(); } // Performing some database operations // Closing the database connection $mysqli -> disconnect(); ?>
In both examples, the code establishes a connection with the database server using different libraries (mysqli and PDO), performs some database operations, and finally disconnects the database connection using the disconnect method of the respective library. Package Library: mysqli or PDO library.