我在MySql中有一个处于本地模式的数据库,而另一个数据库在MariaDB中的另一台服务器中
我在我的database.php文件中配置了很多 如.env
database.php
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', '127.0.0.1'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'test'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'prefix_indexes' => true,
'strict' => true,
'engine' => null,
'modes' => [
'ONLY_FULL_GROUP_BY',
'STRICT_TRANS_TABLES',
'NO_ZERO_IN_DATE',
'NO_ZERO_DATE',
'ERROR_FOR_DIVISION_BY_ZERO',
'NO_ENGINE_SUBSTITUTION',
],
],
'asterisk' => [
'driver' => 'mysql',
'host' => env('ASTERISK_HOST', 'localhost'),
'database' => env('ASTERISK_DATABASE', 'forge'),
'username' => env('ASTERISK_USERNAME', 'forge'),
'password' => env('ASTERISK_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
.env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3307
DB_DATABASE=test
DB_USERNAME=root
DB_PASSWORD=''
ASTERISK_HOST=192.168.2.212
ASTERISK_PORT=3306
ASTERISK_DATABASE=database
ASTERISK_USERNAME=usuario
ASTERISK_PASSWORD='password'
我测试连接的测试路径是Route::get('vicidial','Vicidial\VicidialPruebaController@index');
控制器如下
Vicidial \ VicidialPruebaController.php
<?php
namespace App\Http\Controllers\Vicidial;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\VicidialModel\VicidialList;
class VicidialPruebaController extends Controller
{
public function index(){
$list = VicidialList::find(1);
dd($list);
}
}
模型是
VicidialModel \ VicidialList.php
<?php
namespace App\VicidialModel;
use Illuminate\Database\Eloquent\Model;
class VicidialList extends Model{
/**
* The connection name for the model.
*
* @var string
* @author Luis Morales
*/
protected $connection = 'asterisk';
/**
* The table associated with the model.
*
* @var string
* @author Luis Morales
*/
protected $table = 'vicidial_list';
/**
* The primary key associated with the table.
*
* @var string
* @author Luis Morales
*/
protected $primaryKey = 'lead_id';
/**
* The attributes that are mass assignable.
*
* @var array
* @author Luis Morales
*/
protected $fillable = [
'entry_date',
'modify_date',
'status',
'user',
'vendor_lead_code',
'source_id',
'list_id',
'gmt_offset_now',
'called_since_last_reset',
'phone_code',
'phone_number',
'title',
'first_name',
'middle_initial',
'last_name',
'address1',
'address2',
'address3',
'city',
'state',
'province',
'postal_code',
'country_code',
'gender',
'date_of_birth',
'alt_phone',
'email',
'security_phrase',
'comments',
'called_count',
'last_local_call_time',
'rank',
'owner',
'entry_list_id'
];
/**
* Indicates if the model should be timestamped.
*
* @var bool
* @author Luis Morales
*/
public $timestamps = false;
}
在尝试连接期间发生错误,因为被连接方在一段时间后未正确响应,或者在建立的连接中发生了错误,因为被连接的主机无法进行
这是第二个使用星号的数据库的测试。通过第一个系统,我的系统开始运行
答案 0 :(得分:0)
您应该检查ASTERISK_HOST
:
ASTERISK_PORT=3306
文件中有一个条目.env
,但是您没有在'asterisk'
连接中使用它(没问题,因为它应该是默认端口,但是最好检查一下也)。