简体   繁体   English

laravel MySQL查询生成器

[英]laravel mysql to query builder

i'm relatively new to laravel and i'm having issues when trying to convert this function to laravel's query builder. 我是laravel的新手,尝试将此函数转换为laravel的查询生成器时遇到问题。 This is the function i've been given which also runs a python script to decrypt the database. 这是我提供的功能,该功能还运行python脚本来解密数据库。

Using the documentation from laravel.com you can do something like this: 使用laravel.com提供文档,您可以执行以下操作:

function call($unitId)
{
    $pfContact = DB::table('PFContact')
        ->where('UnitID', $unitId)
        ->latest() // Order by created_at
        ->first([ // Only retrieve these columns
            'Send',
            'Receive',
            'Core',
            'lock'
        ]);

    $pfReadings = DB::table('PFReadings')
        ->get();

    $rowCount = $pfReadings->count();

    foreach ($pfReadings as $i => $reading) {
        echo $i < count($reading) / $rowCount;
        foreach ($reading as $column => $value) {
            echo shell_exec(
                'python3 enc.py ' . $value 
                . ' ' . $pfContact->Send 
                . ' ' . $pfContact->Receive 
                . ' ' . $pfContact->Core 
                . ' ' . $pfContact->lock . ' ' 
                . $unitId . ' l'
            ) . '~';
        }
        echo ';';
    }
}

And although I do not know what arguments this pyhton script needs you should really think this through. 而且,尽管我不知道此pyhton脚本需要哪些参数,但您应该真正考虑一下。 Why would you use PHP for this and not just handle everything from the python (or php) side because this looks over complicated to me. 为什么要使用PHP而不是仅仅处理python(或php)方面的所有内容,因为这对我来说看起来太复杂了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM