laravelにおいてsqliteにアクセスできません。
以下は、設定ファイルである「database.php」です。
php
1<?php 2 3return [ 4 5 /* 6 |-------------------------------------------------------------------------- 7 | Default Database Connection Name 8 |-------------------------------------------------------------------------- 9 | 10 | Here you may specify which of the database connections below you wish 11 | to use as your default connection for all database work. Of course 12 | you may use many connections at once using the Database library. 13 | 14 */ 15 16 'default' => env('DB_CONNECTION', 'sqlite'), 17 18 /* 19 |-------------------------------------------------------------------------- 20 | Database Connections 21 |-------------------------------------------------------------------------- 22 | 23 | Here are each of the database connections setup for your application. 24 | Of course, examples of configuring each database platform that is 25 | supported by Laravel is shown below to make development simple. 26 | 27 | 28 | All database work in Laravel is done through the PHP PDO facilities 29 | so make sure you have the driver for your particular database of 30 | choice installed on your machine before you begin development. 31 | 32 */ 33 34 'connections' => [ 35 36 'sqlite' => [ 37 'driver' => 'sqlite', 38 'database' => env('DB_DATABASE', database_path('database.sqlite')), 39 'prefix' => '', 40 'foreign_key_constraints' => env('DB_FOREIGN_KEYS', true), 41 ], 42 43 'mysql' => [ 44 'driver' => 'mysql', 45 'host' => env('DB_HOST', '127.0.0.1'), 46 'port' => env('DB_PORT', '3306'), 47 'database' => env('DB_DATABASE', 'forge'), 48 'username' => env('DB_USERNAME', 'forge'), 49 'password' => env('DB_PASSWORD', ''), 50 'unix_socket' => env('DB_SOCKET', ''), 51 'charset' => 'utf8mb4', 52 'collation' => 'utf8mb4_unicode_ci', 53 'prefix' => '', 54 'prefix_indexes' => true, 55 'strict' => true, 56 'engine' => null, 57 'options' => extension_loaded('pdo_mysql') ? array_filter([ 58 PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), 59 ]) : [], 60 ], 61 62 'pgsql' => [ 63 'driver' => 'pgsql', 64 'host' => env('DB_HOST', '127.0.0.1'), 65 'port' => env('DB_PORT', '5432'), 66 'database' => env('DB_DATABASE', 'forge'), 67 'username' => env('DB_USERNAME', 'forge'), 68 'password' => env('DB_PASSWORD', ''), 69 'charset' => 'utf8', 70 'prefix' => '', 71 'prefix_indexes' => true, 72 'schema' => 'public', 73 'sslmode' => 'prefer', 74 ], 75 76 'sqlsrv' => [ 77 'driver' => 'sqlsrv', 78 'host' => env('DB_HOST', 'localhost'), 79 'port' => env('DB_PORT', '1433'), 80 'database' => env('DB_DATABASE', 'forge'), 81 'username' => env('DB_USERNAME', 'forge'), 82 'password' => env('DB_PASSWORD', ''), 83 'charset' => 'utf8', 84 'prefix' => '', 85 'prefix_indexes' => true, 86 ], 87 88 ], 89 90 /* 91 |-------------------------------------------------------------------------- 92 | Migration Repository Table 93 |-------------------------------------------------------------------------- 94 | 95 | This table keeps track of all the migrations that have already run for 96 | your application. Using this information, we can determine which of 97 | the migrations on disk haven't actually been run in the database. 98 | 99 */ 100 101 'migrations' => 'migrations', 102 103 /* 104 |-------------------------------------------------------------------------- 105 | Redis Databases 106 |-------------------------------------------------------------------------- 107 | 108 | Redis is an open source, fast, and advanced key-value store that also 109 | provides a richer body of commands than a typical key-value system 110 | such as APC or Memcached. Laravel makes it easy to dig right in. 111 | 112 */ 113 114 'redis' => [ 115 116 'client' => env('REDIS_CLIENT', 'predis'), 117 118 'options' => [ 119 'cluster' => env('REDIS_CLUSTER', 'predis'), 120 ], 121 122 'default' => [ 123 'host' => env('REDIS_HOST', '127.0.0.1'), 124 'password' => env('REDIS_PASSWORD', null), 125 'port' => env('REDIS_PORT', 6379), 126 'database' => env('REDIS_DB', 0), 127 ], 128 129 'cache' => [ 130 'host' => env('REDIS_HOST', '127.0.0.1'), 131 'password' => env('REDIS_PASSWORD', null), 132 'port' => env('REDIS_PORT', 6379), 133 'database' => env('REDIS_CACHE_DB', 1), 134 ], 135 136 ], 137 138]; 139
下記はコントローラー部分である「HelloController.php」です。
php
1<?php 2 3namespace App\Http\Controllers; 4 5use Illuminate\Http\Request; 6use Illuminate\Http\Response; 7use App\Http\Requests\HelloRequest; 8use Validator; 9use Illuminate\Support\Facades\DB; 10 11 12class HelloController extends Controller{ 13 14 public function index(Request $request) 15 { 16 $items = DB::select('select * from people'); 17 return view('hello.index',['items' => $items]); 18 } 19 20 public function post(Request $request) 21 22 { 23 $validate_rule = [ 24 'msg' => 'required', 25 ]; 26 27 $this->validate($request,$validate_rule); 28 $msg = $request->msg; 29 $response = new Response(view('hello.index',['msg' => '「' . $msg . '」をクッキーに保存しました。'])); 30 $response->cookie('msg',$msg,100); 31 return $response; 32 33 } 34 35 36} 37 38
下記はルート部分であるweb.phpです。
php
1<?php 2 3/* 4|-------------------------------------------------------------------------- 5| Web Routes 6|-------------------------------------------------------------------------- 7| 8| Here is where you can register web routes for your application. These 9| routes are loaded by the RouteServiceProvider within a group which 10| contains the "web" middleware group. Now create something great! 11| 12*/ 13 14 15// Route::post('hello','HelloContoroller@post'); 16 17//use App\Http\Middleware\HelloMiddleware; 18 19Route::get('hello','HelloController@index'); 20Route::post('hello','HelloController@post'); 21 22// Route::get('hello/other','HelloController@other'); 23
接続できないということなのですが、具体的には、以下のエラーが「/hello」にアクセスした際に発生してしまいます。
下記は、DatabaseのConnection.php内のコードになります
上記エラーを調べましたら設定ファイル「database.php」のenv関数内の設定が間違っている際に、発生する可能性があるとのことなのですが、特に「database.php」内に記述ミスなどは見当たりません。
どなたか、エラーの解決方法に関しまして、ご助言頂けないでしょうか。
よろしくお願いします
回答1件
あなたの回答
tips
プレビュー