laravel文档好像没有写得很详细 https://docs.golaravel.com/docs/5.3/database/ Using Multiple Database Connections When using multiple connections, you may access each connection via the connection method on the DB facade. The name passed to the connection method
php artisan make:migration create_stocks_table 在项目根目录执行上面的命令后,会在database/migrations目录下生成2016_06_03_100344_create_stocks_table.php(名称与时间有关)文件,修改这个文件就可以了,修改后如下 <?php use Illuminate\Database\Schema\Blueprint; use Illuminate\Database\Migrations\Migration
假设ModelA和ModelB之间是BelongsTo的关系 如果同属于一个数据库连接 那么 public function a(){ return $this->belongsTo("ModelA") } 如果两个模型属于不同的数据库 那么 public function a() { $instance = new ModelA; $instance->setConnection($a_conn); $query = $instance->newQuery(); r
建立student控制器,控制器代码 namespace App\Http\Controllers; use Illuminate\Support\Facades\DB; class StudentController extends Controller{ //添加 public function addstudent(){ $student = DB::insert('insert into student(name,age,gender) values(?,?,?)',['张三',12,2