I am following the tutorial for Doctrine: http://docs.doctrine-project.org/projects/doctrine-orm/en/latest/tutorials/getting-started.html
I changed the bootstrap file to include my database to:
<?php
// bootstrap.php
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
require_once "vendor/autoload.php";
// Create a simple "default" Doctrine ORM configuration for Annotations
$isDevMode = false;
$paths = array(__DIR__."/src");
$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
// or if you prefer yaml or XML
//$config = Setup::createXMLMetadataConfiguration(array(__DIR__."/config/xml"), $isDevMode);
//$config = Setup::createYAMLMetadataConfiguration(array(__DIR__."/config/yaml"), $isDevMode);
// database configuration parameters
$conn = array(
'host' => '*********',
'port' => '3306',
'user' => '********',
'password' => '****',
'dbname' => 'bugs',
'charset' => 'UTF8',
'driver' => 'pdo_sqlite',
'path' => __DIR__ . '/db.sqlite',
);
// obtaining the entity manager
$entityManager = EntityManager::create($conn, $config);
Then, I did the rest and create the tables, etc using the following commnad:
vendor/bin/doctrine orm:schema-tool:create
Later, I logged to my 'myphpadmin' and the database was not there.
Am I missing any step?
Thank you
That is because you are using the driver pdo_sqlite. It is creating an SQLite database and not a MySQL database. It should have created the file db.sqlite.
Change it to pdo_mysql to get the database to show up in phpmyadmin.
Related
New to doctrine php and I followed each instruction to the point. Downloaded doctrine using composer as instructed on http://www.doctrine-project.org/projects/dbal.html and then on my index.php I added this http://docs.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/configuration.html#getting-a-connection only changing the test database credentials.
include_once 'vendor/autoload.php';
$config = new \Doctrine\DBAL\Configuration();
$connectionParams = array(
'dbname' => 'teastdb',
'user' => 'root',
'password' => '',
'host' => 'localhost',
'driver' => 'pdo_mysql',
);
$conn = \Doctrine\DBAL\DriverManager::getConnection($connectionParams, $config);
and this does not work (shows blank page, I even inserted both right and wrong credential for testing purpose). What is wrong?
Here is a screenshot as well
i've got my bootstrap
<?php
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
// Log Filename
define ('LOG_FILENAME', 'clicktocall-'.date("Ymd").'log');
$loader = require "vendor/autoload.php";
// Doctrine parser
Doctrine\Common\Annotations\AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
// Create a simple "default" Doctrine ORM configuration for Annotations
$isDevMode = true;
$config = Setup::createAnnotationMetadataConfiguration(array("./src/acme"), $isDevMode);
// Database configuration parameters
$dbParams = array(
'driver' => 'pdo_mysql',
'host' => 'localhost',
'user' => 'xxx',
'password' => 'yyy',
'dbname' => 'zzz',
);
// Obtaining the entity manager
$em = EntityManager::create($dbParams, $config);
// Setting Logger Monolog
$Logger = new \Monolog\Logger('CTLogger');
$Logger->pushHandler(new \Monolog\Handler\StreamHandler('./log/'.LOG_FILENAME, \Monolog\Logger::INFO));
When i'm trying to execute
vendor\bin\doctrine orm:schema-tool:update --force
I obtain this message
Fatal error: Cannot redeclare class Doctrine\ORM\Mapping\Annotation in E:\www\acme\vendor\doctri
ne\orm\lib\Doctrine\ORM\Mapping\Annotation.php on line 22
I'm just using Doctrine bundle.
Any idea?
Thanks a lot
[Edit]
I've found that the problem is caused by
Doctrine\Common\Annotations\AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
I use this row to parse the annotations for the symfony\validator bundle, without this the validation doesn't work...
I successfully generated entities from an existing mysql database, but I fail when trying to generate repository classes.
My doctrine.config.php
$frapi_config = array(
'database' => array(
'driver' => 'pdo_mysql',
'user' => 'root',
'password' => 'root',
'dbname' => 'PizzaVan',
'host' => 'localhost:3306'
),
'doctrine' => array (
// Base path is /src/frapi/
'entitiesFolder' => "custom/Application/Model"
)
);
My bootstrap.php
//bootstrap.php
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
require_once dirname(__FILE__) . "/../vendor/autoload.php";
require_once "doctrine.config.php";
// Create a simple "default" Doctrine ORM configuration for Annotations
$isDevMode = true;
$config = Setup::createAnnotationMetadataConfiguration(array(__DIR__ . "/../" . $frapi_config["doctrine"]["entitiesFolder"]), $isDevMode, null, null, false);
// database configuration parameters
$conn = $frapi_config["database"];
// obtaining the entity manager
$entityManager = EntityManager::create($conn, $config);
My cli-config.php
require_once "bootstrap.php";
return \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet($entityManager);
As said before, if I run 2 commands from the console
./vendor/bin/doctrine orm:convert-mapping --namespace='custom\\Application\\Model\\' --force --from-database annotation .
and
./vendor/bin/doctrine orm:generate-entities . --generate-annotations=true --generate-methods=true
I get Entities correctly created in the right folder. Now I would like to create custom RepositoryClass, but if I run
./vendor/bin/doctrine orm:generate-repositories .
I get this message : "No Repository classes were found to be processed".
Any solution? Thank you!
I have tried to follow the "steps" detailed on the website but i couldn't make it work:
http://docs.doctrine-project.org/en/latest/reference/configuration.html
I have downloaded the doctrine package.
Then i have installed it using PEAR.
Now, i create a file called "test.php" with the following content:
//loding Setup from the doctrine package...
require 'vendor/Doctrine/ORM/Tools/Setup.php';
Doctrine\ORM\Tools\Setup::registerAutoloadPEAR();
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
$paths = array("/path/to/entities-or-mapping-files");
$isDevMode = false;
// the connection configuration
$dbParams = array(
'driver' => 'pdo_mysql',
'host' => 'localhost',
'user' => 'admin',
'password' => 'mypass',
'dbname' => 'test',
);
$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
$em = EntityManager::create($dbParams, $config);
// or if you prefer yaml or xml
//$config = Setup::createXMLMetadataConfiguration($paths, $isDevMode);
//$config = Setup::createYAMLMetadataConfiguration($paths, $isDevMode);
What else should i do to make it work?
I can not currently do something like:
print_r($em->getRepository("User"));
It shows me many warnings, for example:
Class User does not exist and could not be loaded in
Warning: array_reverse() expects parameter 1 to be array, boolean given in
Warning: Invalid argument supplied for foreach() in ..../Doctrine/ORM/Mapping/ClassMetadataFactory.php
etc. The first one i guess is the key.
Something is missing but i dont know what.
Thanks.
I am learning Doctrine. I config doctrine 2.2.0 by Tarball Download. Now getting trouble when generating-the-database-schema. Can't use command-line tool with the code below:
<?php
// doctrine.php - Put in your application root
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
use Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper;
use Doctrine\DBAL\Tools\Console\Helper\EntityManagerHelper;
use Doctrine\ORM\Tools\Console\ConsoleRunner;
use Symfony\Component\Console\Helper\HelperSet;
$lib = "../DoctrineORM-2.2.0";
require $lib . '/Doctrine/ORM/Tools/Setup.php';
Setup::registerAutoloadDirectory($lib);
$paths = array("/path/to/entities-or-mapping-files");
$isDevMode = false;
$config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
$dbParams = array(
'dbname' => 'mydb',
'user' => 'root',
'password' => '',
'host' => '127.0.0.1',
'driver' => 'pdo_mysql'
);
$em = EntityManager::create($dbParams, $config);
$helperSet = new HelperSet(array(
'db' => new ConnectionHelper($em->getConnection()),
'em' => new EntityManagerHelper($em)
));
ConsoleRunner::run($helperSet);
The error here.
Fatal error: Class 'Doctrine\DBAL\Tools\Console\Helper\EntityManagerHelper' not found in E:\wamp\www\project\doctrine.php on line 30
and I can not find EntityManagerHelper.php under DoctrineORM-2.2.0\Doctrine\DBAL\Tools\Console\Helper .
Seems like EntityManagerHelper is under different namespace:
namespace Doctrine\ORM\Tools\Console\Helper;