Php凭证系统 - 更新代码

I have this voucher system, that works very well. I ust want to change the code to extract vouchers code and value from database.

cart.php Voucher code is :

$cartTotal = 100;
if (isset($_POST['disCode'])) {
    $arr = file('flatfile1.txt');
    $disCode = strtoupper(trim($_POST['disCode']));

    $found = false;

 - List item

    foreach($arr as $str)
    {
        // Skip empty or invalid lines (assuming your file flatfile1.txt has blank lines).
        if (strpos($str, '|') === false)
            continue;

        list($code,$amount,$valz) = explode('|',$str);
        if ($disCode === trim($code))
        {
            // Code found.

            $cartTotal = round($cartTotal/$amount );
            $found = true;
            break;
        }
    }

    if (!$found)
        $mesaj_eroare= "sorry,voucher code: $disCode is not good";
    else


$mesaj_aplicare_voucher =  "succes message here.";

}

And flatfile1.txt has :

TEST20% | 1.20 | 20%

TEST10% | 1.1 | 10%

TEST05% | 1.05 | 5%

test20% is the voucher code, 1.20 is the value of code, and 20% is for a custom message to apear to the user.

I tried to change flatfile1.txt to flatfile1.php where i retrive values from database. Database have this format

TEST20% | 1.20 | 20%

TEST10% | 1.1 | 10%

TEST05% | 1.05 | 5%

And values are recognised in flatfile1.php but when i tried to apply them into cart.php to the voucher system are not recognised.

Need a solution to replace flatfile1.txt to flatfile1.php for automatization of vouchers.