Skip to content

Instantly share code, notes, and snippets.

@roggeo
Last active November 29, 2018 21:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save roggeo/3cd2f3ffc894f9fb2b9851952a76fe4d to your computer and use it in GitHub Desktop.
Save roggeo/3cd2f3ffc894f9fb2b9851952a76fe4d to your computer and use it in GitHub Desktop.
Cli Config Doctrine ORM for Zend Framework 3
<?php
//Insert in config folder as file name cli-config.php
require_once "vendor/autoload.php";
// bootstrap.php
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Tools\Console\ConsoleRunner;
// Create a simple "default" Doctrine ORM configuration for Annotations
$paths = array(__DIR__."/../module/Entities");
$isDevMode = true;
$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode, null, null, false);
// database configuration parameters
$conn = array(
'driver' => 'pdo_mysql',
'host' => 'localhost',
'port' => '3306',
'user' => 'root',
'password' => 'your_password',
'dbname' => 'your_dbname',
'charset' => 'utf8',
'driverOptions' => [
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'
]
);
$entityManager = EntityManager::create($conn, $config);
return ConsoleRunner::createHelperSet($entityManager);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment