代码之家  ›  专栏  ›  技术社区  ›  ashanrupasinghe

如何访问应用程序目录外的数据库

  •  1
  • ashanrupasinghe  · 技术社区  · 6 年前

    我想从mySql数据库中获取所有的使用数据。

    require_once __DIR__.'/../vendor/autoload.php';
    $app = require __DIR__ . '../../bootstrap/app.php';
    $app->boot();
    $user=new \App\User();
    dd(user::all());//get all user details.
    

    Fatal error: Uncaught Error: Call to a member function connection() on null in C:\inetpub\wwwroot\blog2\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php:1138 Stack trace: #0 C:\inetpub\wwwroot\blog2\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php(1104): Illuminate\Database\Eloquent\Model::resolveConnection(NULL) #1 C:\inetpub\wwwroot\blog2\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php(936): Illuminate\Database\Eloquent\Model->getConnection() #2 C:\inetpub\wwwroot\blog2\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php(847): Illuminate\Database\Eloquent\Model->newBaseQueryBuilder() #3 C:\inetpub\wwwroot\blog2\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php(885): Illuminate\Database\Eloquent\Model->newModelQuery() #4 C:\inetpub\wwwroot\blog2\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php(836): Illuminate\Database\Eloquent\Model->newQueryWithoutScopes() #5 C:\inetpub\wwwroot\blog2\vendor\laravel\framework\s in C:\inetpub\wwwroot\blog2\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php on line 1138
    

    我怎样才能得到所有的用户数据。

    1 回复  |  直到 6 年前
        1
  •  2
  •   Sainesh Mamgain    6 年前

    Laravel 5.6中的工作溶液

    <?php
    require __DIR__.'/../vendor/autoload.php';
    $app = require_once __DIR__.'/../bootstrap/app.php';
    $kernel = $app->make(Illuminate\Contracts\Http\Kernel::class);
    $kernel->handle(Illuminate\Http\Request::capture());
    
    $user = \App\User::all()->toArray();
    
    var_dump($user);