私は Doctrine を扱う初心者です。私は彼らのウェブサイトに行き、最新のものと思われるバージョン 2.0 (安定版) を見つけました。いくつかの問題がありましたが、PEAR メソッドを使用してインストールしました。ドキュメンテーションは私にはかなり面倒に思えましたが、インターネットで検索したところ、boostrap ファイルのサンプルが見つかりました。Doctrine 2.0 のドキュメントはここにあります 。
`指示に従い、require_once ('libs/Doctrine/Common/ClassLoader.php') と同様にクラス ロード ファイルをインクルードしました。最初に。
$classLoader = new \Doctrine\Common\ClassLoader('Doctrine', 'libs');
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader('Symfony', 'libs');
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader('Entities', 'libs');
$classLoader->register();
$classLoader = new \Doctrine\Common\ClassLoader('Dao', 'libs');
$classLoader->register();
$config = new \Doctrine\ORM\Configuration();
$config->setMetadataCacheImpl(new \Doctrine\Common\Cache\ArrayCache);
$config->setProxyDir('/Proxies');
$config->setProxyNamespace('Proxies');
$driverImpl = $config->newDefaultAnnotationDriver(array("/Entities"));
$config->setMetadataDriverImpl($driverImpl);
$connectionOptions = array(
'dbname' => 'db',
'user' => 'root',
'password' => 'mypassword',
'host' => '127.0.0.1',
'driver' => 'pdo_mysql',);
$em = \Doctrine\ORM\EntityManager::create($connectionOptions, $config);
// At this point no actual connection to the database is created
$conn = \Doctrine\DBAL\DriverManager::getConnection($connectionOptions);//('mysql: //root:127.0.0.1@127.0.0.1/db');
// The first time the connection is needed, it is instantiated
// This query triggers the connection to be created
$conn->exec('SHOW TABLES');`
メソッド「execute」はバージョン 2 では「exec」であり、バージョン 2 では他の代わりに DriverManager を使用していることがわかりました。今、Doctrine が機能するかどうかをテストしようとすると、出力が得られず、予期しない T_STRING のエラーが発生します。これは、実際にはコマンドが理解されていないことを意味します。
バージョン 1.2 では getPath() を使用したテストがありますが、この関数はバージョン 2.0 には存在しないか、何か間違っている可能性があります。$conn->exec も何もしないことに注意してください。
Windows 7 と WAMP サーバー バージョン 2、PHP 5.3.3 を実行しています。プロジェクト ディレクトリにある Doctrine のフォルダを取り出しました。プロジェクト ディレクトリに追加せずに Doctrine を使用する機会はありますか?
前もって感謝します。