比较来自不同数据库服务器的表

bqucvtff  于 2021-07-26  发布在  Java
关注(0)|答案(0)|浏览(231)

我使用laravel8比较不同数据库服务器中的两个表。我已经在env下设置了两个数据库连接。我还创建了两个模型,一个用于database1,另一个用于database2。现在我想比较一下controller下的database1和database2表。然而,我似乎有一个逻辑错误,我就是想不出来。有人能告诉我如何从一个表中存储最好的行,以便以后比较它们吗?

<?php

        namespace App\Http\Controllers;

        use Illuminate\Http\Request;
        use Illuminate\Support\Facades\DB;
        use App\Models\database1;
        use App\Models\database2;

        class Merge extends Controller
        {
            public function checkDB(){

                $database1 = DB::connection('mysql2');
                $database2 = DB::connection('mysql');

       //Here would like only the entry barcode from this table for later on 

                $sql = "SELECT barcode FROM database1_table1";
                $cache = $database1->select($sql);

                $sql2 = "SELECT * FROM database2_table1 INNER JOIN ON database2_table1.barcode = $cache.barcode";
                $result = $database2->select($sql2);  

                echo "<pre>";
                 print_r($resutl);
                echo "</pre>";

            }
        }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题