第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

使用 Laravel Eloquent 通過第三方“代理”查詢 SQLite

使用 Laravel Eloquent 通過第三方“代理”查詢 SQLite

PHP
不負(fù)相思意 2022-10-14 10:40:42
我正在嘗試使用 Laravel Eloquent 查詢(可選操作)SQLite 數(shù)據(jù)庫(kù)。為此已經(jīng)存在一個(gè)驅(qū)動(dòng)程序,并且非常易于使用。然而,該數(shù)據(jù)庫(kù)是遠(yuǎn)程的并且是視頻游戲的一部分。游戲支持 RCON,它允許我發(fā)送命令,在這種情況下,我可以發(fā)送 SQL 語(yǔ)句。我現(xiàn)在的狀態(tài):通過第三方庫(kù)向遠(yuǎn)程機(jī)器發(fā)送以“sql”為前綴的 SQL 語(yǔ)句:sql SELECT id, level, guild, isAlive FROM characters接收以記錄號(hào)為前綴的行分隔字符串:     id |  level |  guild |  isAlive |#0 1183 |     14 |     60 |        1 |#1  636 |     10 |     60 |        1 |#2   41 |     30 |     60 |        1 |#3   47 |     27 |     60 |        1 |#4   49 |     38 |     60 |        1 |#5  403 |     32 |     60 |        1 |#6   50 |     31 |     60 |        1 |#7 1389 |     44 |     60 |        1 |以特別令人討厭的方法逐行解析輸出,然后手動(dòng)將它們分配給自定義構(gòu)建的模型/類。我真的很想以任何身份合并 Eloquent,而不是使用我自己的自定義類。當(dāng)我打出這篇文章時(shí),我意識(shí)到我不相信我能夠“搭載”現(xiàn)有的 SQLite 驅(qū)動(dòng)程序,而這很可能是一個(gè)全新的驅(qū)動(dòng)程序。但是,對(duì)于那些比我更有經(jīng)驗(yàn)的人,您對(duì)處理這種情況有什么建議或方法嗎?
查看完整描述

1 回答

?
守著一只汪

TA貢獻(xiàn)1872條經(jīng)驗(yàn) 獲得超4個(gè)贊

最終,我處理了 RCON 命令的輸出。缺點(diǎn)是它特別靜態(tài)。我必須圍繞諸如使用 SQL 語(yǔ)句選擇的列并將結(jié)果調(diào)整為適當(dāng)?shù)念愋偷葍?nèi)容進(jìn)行構(gòu)建。

我正在使用https://github.com/gorcon/rcon-cli并圍繞它包裝了一個(gè)查詢類:

class RconDatabase

{

    const RCON_EXECUTABLE = __DIR__ . '/../bin/rcon';


    public function __construct()

    {


    }


    public function query($sql)

    {

        if (!is_executable(self::RCON_EXECUTABLE)) throw new FilePermissionException('Unable to execute RCON');


        $cmd = self::RCON_EXECUTABLE.' -a '.Config::get('rcon.host').':'.Config::get('rcon.port').' -p '.Config::get('rcon.password').' -c "sql '. $sql .'"';

        $output = shell_exec($cmd);


        if ($output == null) throw new RconConnectionException('No response from RCON server');

        if (strpos($output, 'authentication failed') !== false) throw new RconAuthenticationException();

        if (strpos($output, 'dial tcp') !== false) throw new RconNetworkException();


        $lines = preg_split("/((\r?\n)|(\r\n?))/", $output);


        $results = array();

        $last_column = 0;

        for ($i = 0; $i < count($lines); $i++) {

            if (empty($lines[$i])) continue;


            $columns = str_getcsv($lines[$i], '|');


            for ($x = 0; $x < count($columns); $x++) {

                if ($i == 0 && empty($columns[$x])) {

                    $last_column = $x;

                    continue;

                }


                if ($x == 0 && preg_match('/^#[0-9]+\s+(\S+)/', $columns[0], $match))

                    $columns[$x] = $match[1];


                $columns[$x] = trim($columns[$x]);

            }


            if ($i == 0) continue;


            if ($last_column > 0) unset($columns[$last_column]);


            array_push($results, $columns);

        }


        return $results;

    }

}



查看完整回答
反對(duì) 回復(fù) 2022-10-14
  • 1 回答
  • 0 關(guān)注
  • 107 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)