我想连接另一台服务器上的另一个数据库,所以我在database.php中添加了一个连接名称连接如下:
'waev' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'waev.in'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', '*********'),
'username' => env('DB_USERNAME', '*********'),
'password' => env('DB_PASSWORD', '*********'),
'charset' => 'latin1',
'collation' => 'latin1_swedish_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
然后我创建了一个模型,并将其命名为“central_db.php”
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;
class central_db extends Model
{
protected $connection = 'waev';
protected $table = 'usr_waev';
}
这是我的控制器(check_subsController.php),其中我写了一个用于获取数据的查询:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Database\DatabaseManager;
use Illuminate\Support\Facades\DB;
use App\Http\Requests;
use App\central_db;
class check_subsController extends Controller
{
public function fetch(Request $request){
if(\App\central_db::where('device_srno','=',$request->srno)->get()){
return "ok";
}
}
}
但是我收到了此错误
SQLSTATE [42S02]:找不到基表或视图:1146表 'waev.usr_waev'不存在(SQL:select * from
usr_waev
wheredevice_srno
= 0426143201394)
请在我出错的地方帮忙?