How can the use of PHP eval() function be risky when executing code retrieved from a database?

Using the PHP eval() function to execute code retrieved from a database can be risky because it allows for the execution of arbitrary code, which can lead to security vulnerabilities such as code injection attacks. To mitigate this risk, it is recommended to avoid using eval() altogether and instead find alternative ways to achieve the desired functionality, such as using conditional statements or functions.

// Example of how to avoid using eval() when executing code retrieved from a database
$code = "echo 'Hello, World!';"; // Code retrieved from a database

// Alternative approach using conditional statements
if ($condition) {
    echo $code;
}