How can the use of eval() function in PHP be a security risk when storing PHP code in a database?

Using the eval() function in PHP to execute code stored in a database can be a security risk as it allows for arbitrary code execution, making it vulnerable to code injection attacks. To mitigate this risk, it is recommended to avoid using eval() and instead find alternative methods to execute dynamic code securely, such as using conditional statements or predefined functions.

// Avoid using eval() function to execute code stored in a database
$code = "echo 'Hello, World!';";

// Alternative method to execute dynamic code securely
if ($condition) {
    echo $code;
}