crudly / connectly
1.1.2
2020-05-02 21:20 UTC
Requires
- crudly/encrypted: ^1.1
- laravel/framework: ^7.0
Requires (Dev)
- orchestra/testbench: ^5.0
- phpunit/phpunit: ^8.0
This package is auto-updated.
Last update: 2024-09-16 01:33:53 UTC
README
在数据库中存储数据库连接,一切都已加密。
$connectly = Connectly::create([ 'name' => 'My connection', 'config' => [ 'driver' => 'mysql', 'host' => '127.0.0.1', 'port' => '3306', 'database' => 'connectly_test_base', 'username' => 'connectly_user', 'password' => 'hunter2', ], ]); $myCon = Connectly::where('name', 'My connection')->first(); $connection = $myCon->connect(); // This is a Laravel DB connection $connection->table('users')->get();
安装
使用Composer。
$ composer require crudly/connectly
用法
在config
属性中存储Laravel数据库连接的配置。Laravel默认的config/database.php
包含了一些示例,更多详细描述请见此处。
<?php use Crudly\Connectly\Connectly; // ... $newConnection = new Connectly; $newConnection->name = 'My other database'; $newConnection->config = [ 'driver' => 'mysql', 'host' => '127.0.0.1', 'port' => '3306', 'database' => 'connectly_test_base', 'username' => 'connectly_user', 'password' => 'hunter2', ]; $newConnection->save();
Connectly
是一个Eloquent模型,你可以像存储和检索模型一样使用它。
<?php use Crudly\Connectly\Connectly; // ... $storedConnectly = Connectly::latest()->first(); //or $myConnection = Connectly::where('name', 'My other database')->first();
你可以使用实例来弹出新的数据库连接实例,并用它来与查询构建器一起使用。
$connection = $myConnection->connect(); $data = $connection->table('posts')->get();