What are the advantages and disadvantages of using the mysql_query function in PHP for database operations?

When using the mysql_query function in PHP for database operations, one advantage is its simplicity and ease of use for executing SQL queries. However, a major disadvantage is that it is deprecated in newer versions of PHP and poses security risks such as SQL injection vulnerabilities. It is recommended to use prepared statements or an ORM library like PDO for safer and more reliable database operations.

// Using prepared statements with PDO for safer database operations
$pdo = new PDO("mysql:host=localhost;dbname=mydatabase", "username", "password");

$stmt = $pdo->prepare("SELECT * FROM users WHERE id = :id");
$stmt->bindParam(':id', $id);
$stmt->execute();

$result = $stmt->fetchAll();