What are the security concerns related to using mysql_* functions in PHP scripts?
Using mysql_* functions in PHP scripts can lead to security vulnerabilities such as SQL injection attacks. It is recommended to use parameterized queries with prepared statements or use PDO (PHP Data Objects) to interact with the database securely.
// Using PDO to interact with the database securely
$dsn = 'mysql:host=localhost;dbname=database_name';
$username = 'username';
$password = 'password';
try {
$pdo = new PDO($dsn, $username, $password);
$stmt = $pdo->prepare("SELECT * FROM users WHERE username = :username");
$stmt->bindParam(':username', $username);
$stmt->execute();
$result = $stmt->fetchAll();
} catch (PDOException $e) {
echo "Error: " . $e->getMessage();
}