What are the potential security risks of using mysql_connect in PHP scripts to access databases?

Using `mysql_connect` in PHP scripts to access databases can pose security risks such as SQL injection attacks and potential exposure of sensitive database credentials. To mitigate these risks, it is recommended to use prepared statements or parameterized queries with PDO or MySQLi extensions, as they help prevent SQL injection attacks and provide better security for database interactions.

// Using PDO to connect to a MySQL database securely
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";

try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    echo "Connected successfully";
} catch(PDOException $e) {
    echo "Connection failed: " . $e->getMessage();
}