How to create database in doctrine 2

无人久伴 提交于 2019-12-22 05:09:32

问题


I would like to create a database with doctrine 2 and zend framework 2.

I tried to use the command line but it doesn't work because first of all I need to be connected to a database.

Here is the command line that I could use :

When I use the command "php doctrine dbal:run-sql CREATE DATABASE TOTO", I receive an error which tells me that I the database that I selected (but I don't want to select any database) is unknown.

Do you have any idea how I can figure out this problem ?

I really appreciate if I not obliged to use phpmyadmin and create it by my own. I'll prefer to use doctrine to make sure that my code is compatible with other kind of database (such as Mysql/Postegre)

Thank you =D


回答1:


I found the solution.

You just have to specify in your configuration file that the dbname is equals to null.

<?php
return array (
  'doctrine' => array (
'connection' => 
array (
  'orm_default' => 
  array (
    'driverClass' => 'Doctrine\\DBAL\\Driver\\PDOMySql\\Driver',
    'params' => 
    array (
      'host' => 'localhost',
      'port' => '3306',
      'user' => 'root',
      'password' => '',
      'dbname' => null,
      'charset' => 'UTF8',
    ),
  ),
  'orm_poems' => 
  array (
    'driverClass' => 'Doctrine\\DBAL\\Driver\\PDOMySql\\Driver',
    'params' => 
    array (
      'host' => 'localhost',
      'port' => '3306',
      'user' => 'root',
      'password' => 'mot de passe',
      'dbname' => 'poemsV3',
      'charset' => 'UTF8',
    ),
  ),
),
  ),
);

Have a good day everybody =D



来源:https://stackoverflow.com/questions/14937857/how-to-create-database-in-doctrine-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!