Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create database in doctrine 2

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 : enter image description here

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.

enter image description here

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

like image 275
Freezer freezer Avatar asked Feb 18 '13 13:02

Freezer freezer


People also ask

What is doctrine database?

The Doctrine Project is the home to several PHP libraries primarily focused on database storage and object mapping. The core projects are the Object Relational Mapper (ORM) and the Database Abstraction Layer (DBAL) it is built upon. Get Started View Projects.

How do I know my doctrine version?

Check out the file vendor/doctrine/orm/lib/Doctrine/ORM/Version. php , there is a constant in there that shows the version. It's also accessible from a running app but this is easier.

What is Doctrine query?

Doctrine Query Language (DQL) is an Object Query Language created for helping users in complex object retrieval. You should always consider using DQL (or raw SQL) when retrieving relational data efficiently (eg. when fetching users and their phonenumbers).

What is doctrine repository?

A repository in a term used by many ORMs (Object Relational Mappers), doctrine is just one of these. It means the place where our data can be accessed from, a repository of data. This is to distinguish it from a database as a repository does not care how its data is stored.


1 Answers

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

like image 141
Freezer freezer Avatar answered Sep 23 '22 11:09

Freezer freezer