0

When I have set up a ".env" for using two DBs, also made code as below for use it.

but where() method was incorrect to use it.

Could you tell me more detailed usages to use where() method with explanation or tell some link to study?

Thanks in advenced.

$master = DB::connection('master_db')->table('customer_master')
            ->where(['name', '=', 'string'],
                    ['tel', '=', 'integer'],
                    ['address','=', 'string']);

$slave = DB::connection('slave_db')->table('customer_slave')
            ->where(['histories', '=', 'string'])
            ->union($master)
            ->get();
JsWizard
  • 1,663
  • 3
  • 21
  • 48
  • https://laravel.com/docs/5.5/queries#where-clauses – Devon Bessemer Sep 15 '17 at 13:15
  • Not sure what you're asking, it looks correct although I had never seen the array syntax for where() used before. You can dump out the SQL and bindings with `->toSql()` and `->getBindings()` to examine the query itself. – Devon Bessemer Sep 15 '17 at 13:17

1 Answers1

0

Write the query like this:

$master = DB::connection('master_db')->table('customer_master')
    ->where([
        'name' => 'string',
        'tel' => 'integer',
        'address' => 'string'
    ]);

$slave = DB::connection('slave_db')->table('customer_slave')
    ->where('histories', 'string')
    ->union($master)
    ->get();

Here the array syntax has been tweaked for $master and where() tweaked for $slave. The = comparison is the default so no need to specify here.

Harry
  • 2,429
  • 4
  • 21
  • 26