-2
我一直在努力使這項工作在過去一個多小時左右。無法連接到數據庫 - 沒有選擇數據庫錯誤
我在嘗試在laravel中執行查詢時出現錯誤。
精確誤差如下:
exception 'PDOException' with message 'SQLSTATE[3D000]: Invalid catalog name: 1046 No database selected' in D:\www\testapp\vendor\laravel\framework\src\Illuminate\Database\Connection.php:272
Stack trace:
#0 D:\www\testapp\vendor\laravel\framework\src\Illuminate\Database\Connection.php(272): PDO->prepare('select count(*)...')
#1 D:\www\testapp\vendor\laravel\framework\src\Illuminate\Database\Connection.php(521): Illuminate\Database\Connection->Illuminate\Database\{closure}(Object(Illuminate\Database\MySqlConnection), 'select count(*)...', Array)
#2 D:\www\testapp\vendor\laravel\framework\src\Illuminate\Database\Connection.php(277): Illuminate\Database\Connection->run('select count(*)...', Array, Object(Closure))
#3 D:\www\testapp\vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php(1028): Illuminate\Database\Connection->select('select count(*)...', Array)
#4 D:\www\testapp\vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php(1018): Illuminate\Database\Query\Builder->runSelect()
#5 D:\www\testapp\vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php(1005): Illuminate\Database\Query\Builder->getFresh(Array)
#6 D:\www\testapp\vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php(1369): Illuminate\Database\Query\Builder->get(Array)
#7 D:\www\testapp\vendor\laravel\framework\src\Illuminate\Database\Query\Builder.php(1311): Illuminate\Database\Query\Builder->aggregate('count', Array)
#8 [internal function]: Illuminate\Database\Query\Builder->count()
#9 D:\www\testapp\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Builder.php(786): call_user_func_array(Array, Array)
#10 D:\www\testapp\app\routes.php(67): Illuminate\Database\Eloquent\Builder->__call('count', Array)
#11 D:\www\testapp\app\routes.php(67): Illuminate\Database\Eloquent\Builder->count()
#12 [internal function]: {closure}()
#13 D:\www\testapp\vendor\laravel\framework\src\Illuminate\Routing\Route.php(80): call_user_func_array(Object(Closure), Array)
#14 D:\www\testapp\vendor\laravel\framework\src\Illuminate\Routing\Route.php(47): Illuminate\Routing\Route->callCallable()
#15 D:\www\testapp\vendor\laravel\framework\src\Illuminate\Routing\Router.php(1016): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request))
#16 D:\www\testapp\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(574): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))
#17 D:\www\testapp\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(550): Illuminate\Foundation\Application->dispatch(Object(Illuminate\Http\Request))
#18 D:\www\testapp\public\index.php(50): Illuminate\Foundation\Application->run()
#19 {main}
我的config/database.php中是如下:
'connections' => array(
'mysql' => array(
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'testdatabase',
'username' => 'MYUSER',
'password' => 'MYPASSWORD',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
),
),
觸發此錯誤代碼是:
$users = DB::table('users')->get();
print_r($users . "users");
能有人請幫助,我檢查給定的MySQL用戶的權限,我也用root帳戶嘗試過,但迄今爲止無濟於事。
你確定指定的數據庫是否存在? –
是的,它確實存在 – Sahil
嘗試127.0.0.1一次作爲主機 –