Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php illumb\Database\QueryException(2002)SQLSTATE[HY000][2002]没有这样的文件或目录(SQL:select*from`rents`)_Php_Mysql_Laravel_Laravel 5.4 - Fatal编程技术网

Php illumb\Database\QueryException(2002)SQLSTATE[HY000][2002]没有这样的文件或目录(SQL:select*from`rents`)

Php illumb\Database\QueryException(2002)SQLSTATE[HY000][2002]没有这样的文件或目录(SQL:select*from`rents`),php,mysql,laravel,laravel-5.4,Php,Mysql,Laravel,Laravel 5.4,我正在尝试将Laravel项目连接到现有数据库 我一直遵循着这个原则;但是,我仍然遇到以下错误: Illumb\Database\QueryException(2002)SQLSTATE[HY000][2002] 没有这样的文件或目录(SQL:select*fromrents) 这是我的密码: web.php Route::get('/', [ 'uses' => 'RentsController@index' ]); <?php namespace App\Ht

我正在尝试将Laravel项目连接到现有数据库

我一直遵循着这个原则;但是,我仍然遇到以下错误:

Illumb\Database\QueryException(2002)SQLSTATE[HY000][2002] 没有这样的文件或目录(SQL:select*from
rents

这是我的密码:

web.php

Route::get('/', [
    'uses' => 'RentsController@index'
    ]);
<?php

namespace App\Http\Controllers;

use App\Rent;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;


class RentsController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {   
        $rents = Rent::all();
        return view('welcome', ['rents' => $rents]);
    }

    ...
}
<?php

namespace App;
use Illuminate\Database\Eloquent\Model;


class Rent extends Model {
    protected $table = 'rents';
}
<!doctype html>
<html>
    <head>
    </head>
    <body>
        <ul>
            @foreach ($rents as $rent)
                <li>{{ $rent->title }}</li>
            @endforeach
        </ul>
    </body>
</html>
RentsController.php

Route::get('/', [
    'uses' => 'RentsController@index'
    ]);
<?php

namespace App\Http\Controllers;

use App\Rent;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;


class RentsController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {   
        $rents = Rent::all();
        return view('welcome', ['rents' => $rents]);
    }

    ...
}
<?php

namespace App;
use Illuminate\Database\Eloquent\Model;


class Rent extends Model {
    protected $table = 'rents';
}
<!doctype html>
<html>
    <head>
    </head>
    <body>
        <ul>
            @foreach ($rents as $rent)
                <li>{{ $rent->title }}</li>
            @endforeach
        </ul>
    </body>
</html>

各位,谢谢你们的帮助

我想出来了。问题出在DB_主机上

我正在本地运行页面(即php artisan Service),数据库处于联机状态。我无法访问本地计算机上的数据库。这就是它无法连接的原因

因此,我将其放在实际主机上,而不是DB_HOST=localhost或127.0.0.1

例如:

DB_HOST=hostname_from_server
DB_PORT=3306
DB_DATABASE=database_name_on_server
DB_USERNAME=username_on_server
DB_PASSWORD=password_on_server
然后,我需要清除终端中的缓存:

php artisan config:cache
php artisan cache:clear

道具到@寻求帮助

数据库表
rents
是否存在?您能够连接到任何其他db表吗?可能想看看这个:好问题,谢谢您的快速回复。是的,“租金”表确实存在。不,很遗憾,我无法连接到任何其他表。可能是Thank@IzzEps的副本,我也已经查看了该页面。不幸的是,这些建议都无济于事。我想这里唯一的一点是,我试图连接到一个已经存在的数据库,而不是通过Laravel本身创建它。在这种情况下,我不需要任何迁移。