存储库 - > findAll会出现未知的数据库错误

时间:2018-01-24 12:45:39

标签: php symfony doctrine

我刚开始使用symfony。我用twig,doctrine maker安装了SF4 ......

我创建了自己的数据库' Autotrader',我创建了一个迁移并迁移了它。

但是每当我尝试从数据库中获取数据时,我都会收到以下错误:

screenshot of error

这是我使用的代码:

<?php

namespace App\Controller;

use App\Entity\Car;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;

class CarController extends Controller
{

    public function index()
    {
        $repository = $this->getDoctrine()->getRepository('App:Car');
        $cars = $repository->findAll();

        return $this->render('Car/list.html.twig', array(
            "title" => "Our cars",
            'cars' => $cars
        ));
    }
}

参数配置:

parameters:
# Adds a fallback DATABASE_URL if the env var is not set.
# This allows you to run cache:warmup even if your
# environment variables are not available yet.
# You should not need to change this value.
env(DATABASE_URL): ''

doctrine:
    dbal:
        # configure these for your database server
        driver: 'mysql'
        server_version: '5.7'
        charset: 'utf8mb4'
        dbname:               'autotrader'
        host:                 '127.0.0.1'
        port:                  3306
        user:                 'root'
        password:             'secret'

        # With Symfony 3.3, remove the `resolve:` prefix
        url: '%env(resolve:DATABASE_URL)%'
    orm:
        auto_generate_proxy_classes: '%kernel.debug%'
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true
        mappings:
            App:
                is_bundle: false
                type: annotation
                dir: '%kernel.project_dir%/src/Entity'
                prefix: 'App\Entity'
                alias: App

2 个答案:

答案 0 :(得分:0)

这是未知数据库错误。

您确定已在正确的localhost路径和doctrine.yml文件中提到的端口号创建了Autotrader db吗?

另外,在你的doctrine.yml替换中 dbname: 'autotrader' dbname: Autotrader protected void gvResults_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e) { GridView gv = (GridView)sender; gv.EditIndex = -1; BindGrid2(); } 然后再试一次!!

答案 1 :(得分:0)

我弄清楚问题是什么。 我在vagrant / homestead运行我的应用程序并迁移到localy,难怪没有找到数据库