I've installed Doctrine using composer, and when I try to create the database I get the error:
#!/usr/bin/env php
Why am I seeing this error - no database is created. I obtain the same error if I run update --force. I've also tried orm:schema-tool:create, and I've also tried running the doctrine php file directly php ./vendor/bin/doctrine.php orm:schema:create with the same error.
I have an bootstrap file and a cli-config file as such
// bootstrap.php
<?php
require_once 'vendor/autoload.php';
// Create a simple "default" Doctrine ORM configuration for Annotations
$isDevMode = true;
$config = \Doctrine\ORM\Tools\Setup::createAnnotationMetadataConfiguration(array(__DIR__."/"), $isDevMode);
// database configuration parameters
$conn = array(
'driver' => 'pdo_sqlite',
'path' => __DIR__ . '/db.sqlite',
);
// obtaining the entity manager
$entityManager = \Doctrine\ORM\EntityManager::create($conn, $config);
// cli-config.php
<?php
require_once "bootstrap.php";
return \Doctrine\ORM\Tools\Console\ConsoleRunner::createHelperSet($entityManager);
After much debugging, the path in this line is horribly wrong:
$config = \Doctrine\ORM\Tools\Setup::createAnnotationMetadataConfiguration(array(__DIR__."/"), $isDevMode);
Fixing it so it points to where the class files with mapping data is stored fixed it.
Related
I'm doing my own website and i'm using a PDO library here. I have somes library working fine but this one for any reason cannot be "detected"
Files in the folder:
Installed lib using composer => /main/assets/
File where i want to use the lib => /main/user/index.php
Lib path => /main/assets/vendor/faapz/pdo/...
Reproduce this:
1: In a folder (main), create another folder named "assets", then execute the command "composer require faapz/pdo" (this require an installation of composer)
2: In the folder (main), create folder named "user" and create new php file.
3: Use this code
<?php
// => Class 'FaaPz\PDO\Database' not found in ...\main\user\file.php on line 10
$parent_dir = dirname(__DIR__);
require $parent_dir . '/assets/vendor/autoload.php';
$db = new \PDO('mysql:dbname=your_db_name;host=your_db_host;charset=utf8mb4', 'root', ''); // Working lib
$query = 'mysql:host=your_db_host;dbname=your_db_name;charset=utf8';
$user = 'root';
$pass = '';
$database = new FaaPz\PDO\Database($query, $user, $pass); // Not working lib => Class 'FaaPz\PDO\Database' not found in ...\main\user\file.php on line 10
$auth = new \Delight\Auth\Auth($db); // Working lib
?>
I found the package "ext-pdo" work for my problem. Just install it using composer with the following command => composer require ext-pdo
I'm trying to use Doctrine MongoDB ODM 2.0 beta on a project with the Yii2 framework, with composer version 1.8.4 and PHP 7.2, but I keep getting the error Fatal error: Uncaught Error: Call to a member function add() on boolean where the code runs $loader->add('Documents', __DIR__);
bootstrap.php file (in DIR/bootstrap.php):
<?php
use Doctrine\Common\Annotations\AnnotationRegistry;
use Doctrine\ODM\MongoDB\Configuration;
use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver;
if ( ! file_exists($file = 'C:/path/to/vendor/autoload.php')) {
throw new RuntimeException('Install dependencies to run this script.');
}
$loader = require_once $file;
$loader->add('Documents', __DIR__);
AnnotationRegistry::registerLoader([$loader, 'loadClass']);
$config = new Configuration();
$config->setProxyDir(__DIR__ . '/Proxies');
$config->setProxyNamespace('Proxies');
$config->setHydratorDir(__DIR__ . '/Hydrators');
$config->setHydratorNamespace('Hydrators');
$config->setDefaultDB('fsa');
$config->setMetadataDriverImpl(AnnotationDriver::create(__DIR__ . '/Documents'));
$dm = DocumentManager::create(null, $config);
I already tried looking at How to properly Autoload Doctrine ODM annotations? and Laravel & Couchdb-ODM - The annotation "#Doctrine\ODM\CouchDB\Mapping\Annotations\Document" does not exist, or could not be auto-loaded and a host of other threads I can't quite recall for help, but I couldn't figure out a solution.
I also tried commenting out the lines below
if ( ! file_exists($file = 'C:/path/to/vendor/autoload.php')) {
throw new RuntimeException('Install dependencies to run this script.');
}
$loader = require_once $file;
$loader->add('Documents', __DIR__);
AnnotationRegistry::registerLoader([$loader, 'loadClass']);
and ran composer dump-autoload and on command line it returned Generated autoload files containing 544 classes, but then I got the problem
[Semantical Error] The annotation "#Doctrine\ODM\MongoDB\Mapping\Annotations\Document" in class Documents\Message does not exist, or could not be auto-loaded.
So the annotations are not auto-loading, and I have no idea how to fix that.
In the model I have:
<?php
namespace Documents;
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
use \Doctrine\ODM\MongoDB\Mapping\Annotations\Document;
/** #ODM\Document */
class Message
{
/** #ODM\Id */
private $id;
/** #ODM\Field(type="int") */
private $sender_id;
...
I also posted a thread on github at https://github.com/doctrine/mongodb-odm/issues/1976. One commenter stated that "By default, the composer autoload file returns the autoloader in question, which seems to not be the case for you." How can I fix that? The only information I can find online is to put (inside composer.json) the lines:
"autoload": {
"psr-4": {
"Class\\": "src/"
}
},
but then what class should I be loading?
I'm very confused and being pretty new to all these tools (mongodb, yii2, etc.) doesn't help at all. I'm not sure what other information would be helpful else I would post it.
Thanks in advance.
So turns out that the problem (as was mentioned in https://github.com/doctrine/mongodb-odm/issues/1976) was that autoload.php was required twice - once in bootstrap.php and once in web/index.php (of the framework). After the require line in index.php was removed, everything worked fine.
I am trying to setup the AWS sdk for php on my local environment.
I am neither Composer nor PHAR.I am just extracting it from the zip file and adding the extracted folder to my c:\wamp\www\ directory.I created a index.php file to access the sdk classes.The index file is
<?php
define('AWS_KEY', '');
define('AWS_SECRET_KEY', '');
define('HOST', 'http://www.example.com');
// require the AWS SDK for PHP library
require 'build/aws-autoloader.php';
//require_once '';
use Aws\S3\S3Client;
//require_once('src/Aws/S3/S3Client.php');
// Establish connection with DreamObjects with an S3 client.
$client = Aws\S3\S3Client::factory(array(
'base_url' => HOST,
'key' => AWS_KEY,
'secret' => AWS_SECRET_KEY
));
?>
The autoloader.php is below.Here I updated the path for UniversalClassLoader.php file as I had to download it from git.In the AWS_FILE_PREFIX variable I updated the root path for all classes.
require_once 'UniversalClassLoader.php';
if (!defined('AWS_FILE_PREFIX')) {
define('AWS_FILE_PREFIX', 'C:\wamp\www\awssdk\src\Aws');
}
$classLoader = new UniversalClassLoader();
$classLoader->registerNamespaces(array(
'Aws' => AWS_FILE_PREFIX,
'Guzzle' => AWS_FILE_PREFIX,
'Symfony' => AWS_FILE_PREFIX,
'Doctrine' => AWS_FILE_PREFIX,
'Psr' => AWS_FILE_PREFIX,
'Monolog' => AWS_FILE_PREFIX
));
$classLoader->register();
return $classLoader;
BUt I keep getting the error class not found for S3Client class in the index.php file.I cross checked the path using require and it finds the class.
Can someone help me point what am I doing wrong here ? I have no prior experience of using namespaces or autoloaders and cannot debug this issue.
I start with doctrine and want to create a db or php class from table with doctrine.
First i try create db. My bootstrap.php:
<?php
use Doctrine\ORM\Tools\Setup;
use Doctrine\ORM\EntityManager;
require_once "vendor/autoload.php";
require_once "src/BugRepository.php";
$isDevMode = true;
$config = Setup::createAnnotationMetadataConfiguration(array(__DIR__."/src"), $isDevMode);
$conn = array(
'driver' => 'pdo_pgsql',
'user' => 'postgres',
'password' => '123456',
'host' => 'localhost',
'dbname' =>'testdata',
);
$entityManager = EntityManager::create($conn, $config);
and i do:
php vendor/bin/doctrine doctrine:database:create
my output:
SRC_DIR="`pwd`"
cd "`dirname "$0"`"
cd "../doctrine/orm/bin"
BIN_TARGET="`pwd`/doctrine"
cd "$SRC_DIR"
"$BIN_TARGET" "$#"
But db testdatanot created.
Same with creating php class from table:
php vendor/bin/doctrine doctrine:mapping:import YourAppBundle yml --filter="bugs"
But yml file not created.
Whats can be wrong?
There are also a bin folder in vendor/doctrine/orm/bin/ you can use this one like this
php vendor/doctrine/orm/bin/doctrine orm:schema-tool:create
make sure you have root folder and a cli-config.php file is present in root folder.
https://groups.google.com/forum/#!msg/doctrine-user/_ph183Kh-5o/_P_coljB-dcJ
Having never touched Doctrine before (either 1 or 2), I am following this tutorial for Doctrine 2.
I'm at the point where I use the command line to generate the database schema. This is the cli-config.php file, as per the tutorial:
<?php
$cliConfig = new Doctrine\Common\Cli\Configuration();
$cliConfig->setAttribute('em', $entityManager);
When I run it though, I just get an error:
Fatal error: require(): Failed opening required 'Doctrine\Common\Cli\Configuration.php'
Because that class referenced by the cli-config.php file doesn't exist. I've also tried blanking the cli-config.php file, which of course doesn't work either - says that "The helper "em" is not defined."
I'm using version 2.0.0BETA3. I know that this is a beta version, so they could have changed some files around, but I can't find that class anywhere.
Any ideas on how to get it working?
The docs in the XML Getting Started are outdated in this regard. Please see the Tools section in the manual on how to configure the CLI Tool:
http://docs.doctrine-project.org/projects/doctrine-orm/en/2.0.x/reference/tools.html
All the rest still works as described. I will update this part asap.
Assuming you installed Doctrine using pear
$ sudo pear install pear.doctrine-project.org/doctrineORM
which will install the three 'Doctrine 2' packages: DoctrineCommon, DoctrineDBAL, and DoctrineORM. On Ubuntu, these packages will be located in /usr/share/php/Doctrine, and the doctrine command line utility, will be installed into /usr/bin.
With this setup, this is a version of cli-config.php you can use (note: DIR should have two underscores before and after it. For some reason they didn't display).
<?php
require ‘Doctrine/ORM/Tools/Setup.php’;
// Setup Autoloader (1)
Doctrine\ORM\Tools\Setup::registerAutoloadPEAR();
require_once 'Doctrine/Common/ClassLoader.php';
$classLoader = new Doctrine\Common\ClassLoader('Entities', __DIR__);
$classLoader->register();
$classLoader = new Doctrine\Common\ClassLoader('Proxies', __DIR__);
$classLoader->register();
$config = new \Doctrine\ORM\Configuration();
$config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache);
$driverImpl = $config->newDefaultAnnotationDriver(array(__DIR__."/Entities"));
$config->setMetadataDriverImpl($driverImpl);
$config->setProxyDir(__DIR__ . '/Proxies');
$config->setProxyNamespace('Proxies');
$connectionOptions = array(
'driver' => 'pdo_mysql',
'dbname' => 'bugs',
'user' => 'bugs',
'password' => 'xyzabc',
'host' => 'localhost' );
$em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config);
$helperSet = new \Symfony\Component\Console\Helper\HelperSet(array(
'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()),
'em' => new \Doctrine\ORM\Tools\Console\Helper\EntityManagerHelper($em)
));