Doctrine 和 Postgresql,从数据库问题生成模型

发布于 2024-10-03 09:35:19 字数 1605 浏览 1 评论 0原文

我有一个 Postgresql 9.0 数据库,我正在尝试使用 Doctrine ORM 1.2 从数据库生成模型。

这是我的代码:

<?php
require_once 'Doctrine.php';
spl_autoload_register(array('Doctrine', 'autoload'));
spl_autoload_register(array('Doctrine_Core', 'modelsAutoload'));
$manager = Doctrine_Manager::getInstance(); 
$conn = Doctrine_Manager::connection('pgsql://postgres:[email protected]/erp','doctrine');
$conn->setAttribute( Doctrine_Core::ATTR_PORTABILITY, Doctrine_Core::PORTABILITY_FIX_CASE | PORTABILITY_RTM);
$conn->setAttribute( Doctrine_Core::ATTR_QUOTE_IDENTIFIER, true);
$manager->setAttribute(Doctrine_Core::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
Doctrine_Core::loadModels('../application/models');
Doctrine_Core::generateModelsFromDb('../application/models', array('doctrine'), array('generateTableClasses' => true));
?>

当我运行页面时,我收到此错误:

Fatal error: Uncaught exception 'Doctrine_Connection_Pgsql_Exception' with message 'SQLSTATE[42P01]: Undefined table: 7 ERROR: missing FROM-clause entry for table "t" LINE 6: ... t.typtype ... ^. Failing Query: "SELECT ordinal_position as attnum, column_name as field, udt_name as type, data_type as complete_type, t.typtype AS typtype, is_nullable as isnotnull, column_default as default, ( SELECT 't' in D:\Doctrine-1.2.3\Doctrine-1.2.3\Doctrine\Connection.php on line 1082

值得一提的是,这段代码对于 mysql 来说工作得非常完美(通过在curse连接中使用 mysql:// ... ),但是很难获取它与 postgresql 9.0 一起使用。

有什么想法吗?

I have a database in Postgresql 9.0 and I'm trying to use Doctrine ORM 1.2 to generate models from db.

Here is my code:

<?php
require_once 'Doctrine.php';
spl_autoload_register(array('Doctrine', 'autoload'));
spl_autoload_register(array('Doctrine_Core', 'modelsAutoload'));
$manager = Doctrine_Manager::getInstance(); 
$conn = Doctrine_Manager::connection('pgsql://postgres:[email protected]/erp','doctrine');
$conn->setAttribute( Doctrine_Core::ATTR_PORTABILITY, Doctrine_Core::PORTABILITY_FIX_CASE | PORTABILITY_RTM);
$conn->setAttribute( Doctrine_Core::ATTR_QUOTE_IDENTIFIER, true);
$manager->setAttribute(Doctrine_Core::ATTR_AUTO_ACCESSOR_OVERRIDE, true);
Doctrine_Core::loadModels('../application/models');
Doctrine_Core::generateModelsFromDb('../application/models', array('doctrine'), array('generateTableClasses' => true));
?>

and when I run the page, I get this error:

Fatal error: Uncaught exception 'Doctrine_Connection_Pgsql_Exception' with message 'SQLSTATE[42P01]: Undefined table: 7 ERROR: missing FROM-clause entry for table "t" LINE 6: ... t.typtype ... ^. Failing Query: "SELECT ordinal_position as attnum, column_name as field, udt_name as type, data_type as complete_type, t.typtype AS typtype, is_nullable as isnotnull, column_default as default, ( SELECT 't' in D:\Doctrine-1.2.3\Doctrine-1.2.3\Doctrine\Connection.php on line 1082

It's worth to mention, this code is working perfectly for mysql (by having mysql:// ... in the connection ofcurse), but having trouble to get it working with postgresql 9.0.

Any idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

扛刀软妹 2024-10-10 09:35:19

听起来像 Doctrine 中的这个错误: http://www.doctrine-project.org/ jira/浏览/DC-919

Sounds like this bug in Doctrine: http://www.doctrine-project.org/jira/browse/DC-919

又爬满兰若 2024-10-10 09:35:19

尝试在表名或列名中添加引号。

导出表时找到正确的命名。

我的问题是有人在表名中添加了引号。

$sql='SELECT "id","name",
   ("f1"=\'aaa\' OR
   "f1"=\'bbb\') AS "myflag"
   FROM "mytable"';

Try to add quotes to table name, or column names.

Find right naming while exporting a table.

My problem was that someone added quotes to table name.

$sql='SELECT "id","name",
   ("f1"=\'aaa\' OR
   "f1"=\'bbb\') AS "myflag"
   FROM "mytable"';
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文