0

我是处理教义的初学者。我去了他们的网站,发现 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 的文件夹,但我并没有真正了解 PEAR 安装的目的是什么?有没有机会在不添加到项目目录的情况下使用 Doctrine?

提前致谢。

4

2 回答 2

0

我不能从你如何描述这个问题说出来,但我建议你使用一个调试器,比如嵌入在 Zend Studio 中的调试器(或者你可以使用任何基于 Eclipse 的 IDE 设置 Zend,比如 Aptana)。这将使事情变得更加清晰。

于 2011-07-07T20:00:16.977 回答
0

为什么需要触发连接?它在第一次使用时会延迟连接。在 EntityManager::create 方法之后你应该很好。

于 2010-12-28T12:15:40.090 回答