laravel 5.5 定时任务连接sqlserver数据库报错问题


问题:在定时任务处理,app\Console\Kernel.php文件的schedule方法中连接sqlsrv报错:"不能找到driver。"
问题分析:
我的项目是连接mysql(默认) 和 sqlsrv数据库。
1、在schedule方法内调用mysql数据库驱动是没问题。
2、在项目其他地方连接sqlsrv数据库驱动没任何问题。

我的开发环境:win10, wamp, apache 2.4.27, php 7.1.9

app\Console\Kernel.php文件的schedule方法的代码:
protected function schedule(Schedule $schedule)
{
$schedule->call(function(){
$users = DB::connection('sqlsrv')->table('Emp_BaseInfo')->get();
Log::info($users->Emp_id);
})->everyMinute();
}

报错日志:
[2018-06-07 16:44:51] local.ERROR: could not find driver (SQL: select top 1 from [Emp_BaseInfo]) {"exception":"[object] (Illuminate\Database\QueryException(code: 0): could not find driver (SQL: select top 1 from [Emp_BaseInfo]) at D:\wamp\www\eastpoint\vendor\laravel\framework\src\Illuminate\Database\Connection.php:664, PDOException(code: 0): could not find driver at D:\wamp\www\eastpoint\vendor\laravel\framework\src\Illuminate\Database\Connectors\Connector.php:67)
[stacktrace]
#0 D:\wamp\www\eastpoint\vendor\laravel\framework\src\Illuminate\Database\Connection.php(624): Illuminate\Database\Connection->runQueryCallback('select top 1 ...', Array, Object(Closure))
#1 D:\wamp\www\eastpoint\vendor\laravel\framework\src\Illuminate\Database\Connection.php(333): Illuminate\Database\Connection->run('select top 1
...', Array, Object(Closure))
#2 D:\wamp\www\eastpoint\vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php(1719): Illuminate\Database\Connection->select('select top 1 * ...', Array, true)
#3 D:\wamp\www\eastpoint\vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php(1704): Illuminate\Database\Query\Builder->runSelect()
#4 D:\wamp\www\eastpoint\vendor\laravel\framework\src\Illuminate\Database\Concerns\BuildsQueries.php(77): Illuminate\Database\Query\Builder->get(Array)
#5 D:\wamp\www\eastpoint\app\Console\Kernel.php(50): Illuminate\Database\Query\Builder->first()
#6 [internal function]: App\Console\Kernel->App\Console\{closure}()
#7 D:\wamp\www\eastpoint\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(29): call_user_func_array(Object(Closure), Array)
#8 D:\wamp\www\eastpoint\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(75): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#9 D:\wamp\www\eastpoint\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Object(Closure), Object(Closure))
#10 D:\wamp\www\eastpoint\vendor\laravel\framework\src\Illuminate\Container\Container.php(549): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Object(Closure), Array, NULL)
#11 D:\wamp\www\eastpoint\vendor\laravel\framework\src\Illuminate\Console\Scheduling\CallbackEvent.php(74): Illuminate\Container\Container->call(Object(Closure), Array)
#12 D:\wamp\www\eastpoint\vendor\laravel\framework\src\Illuminate\Console\Scheduling\ScheduleRunCommand.php(59): Illuminate\Console\Scheduling\CallbackEvent->run(Object(Illuminate\Foundation\Application))
#13 [internal function]: Illuminate\Console\Scheduling\ScheduleRunCommand->handle()
#14 D:\wamp\www\eastpoint\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(29): call_user_func_array(Array, Array)
#15 D:\wamp\www\eastpoint\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(87): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}()
#16 D:\wamp\www\eastpoint\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php(31): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure))
#17 D:\wamp\www\eastpoint\vendor\laravel\framework\src\Illuminate\Container\Container.php(549): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL)
#18 D:\wamp\www\eastpoint\vendor\laravel\framework\src\Illuminate\Console\Command.php(183): Illuminate\Container\Container->call(Array)
#19 D:\wamp\www\eastpoint\vendor\symfony\console\Command\Command.php(252): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#20 D:\wamp\www\eastpoint\vendor\laravel\framework\src\Illuminate\Console\Command.php(170): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle))
#21 D:\wamp\www\eastpoint\vendor\symfony\console\Application.php(946): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#22 D:\wamp\www\eastpoint\vendor\symfony\console\Application.php(248): Symfony\Component\Console\Application->doRunCommand(Object(Illuminate\Console\Scheduling\ScheduleRunCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#23 D:\wamp\www\eastpoint\vendor\symfony\console\Application.php(148): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#24 D:\wamp\www\eastpoint\vendor\laravel\framework\src\Illuminate\Console\Application.php(88): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#25 D:\wamp\www\eastpoint\vendor\laravel\framework\src\Illuminate\Foundation\Console\Kernel.php(121): Illuminate\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#26 D:\wamp\www\eastpoint\artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput))
#27 {main}
"}


点赞 取消点赞 收藏 取消收藏

<< 上一篇: 安装Homestead问题

>> 下一篇: blade模版