// Connect to the database $conn = mysqli_connect($servername, $username, $password, $dbname); // Perform database operations here... // Close the database connection mysqli_close($conn);
// Connect to the database $dsn = "mysql:host=$servername;dbname=$dbname"; $conn = new PDO($dsn, $username, $password); // Perform database operations here... // The database connection is automatically closed when the PDO object is destroyedPackage/Library: PHP Core Both examples above use the built-in functions and classes provided by PHP core, and do not require any external package or library.