How can the use of functions like mysql_pconnect improve the reliability of database connections in PHP scripts?

Using functions like mysql_pconnect in PHP scripts can improve the reliability of database connections by allowing for persistent connections. Persistent connections remain open between different requests, reducing the overhead of establishing a new connection each time a script is executed. This can lead to faster execution times and better performance for PHP applications that require frequent database interactions.

<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

// Create a persistent database connection
$conn = mysql_pconnect($servername, $username, $password);

// Check connection
if (!$conn) {
    die("Connection failed: " . mysql_error());
}

mysql_select_db($dbname, $conn);
echo "Connected successfully";
?>