2010-11-21 71 views
1

我在Postgresql 9.0中有一個數據庫,我試圖使用Doctrine ORM 1.2從數據庫生成模型。Doctrine和Postgresql,從數據庫生成模型問題

這裏是我的代碼:

<?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(具有mysql:// ...在連接中),但無法使它與postgresql 9.0一起工作。

有什麼想法?

回答

0

嘗試引號添加到表名或列名。

在導出表格時找到正確的命名。

我的問題是有人給表名添加了引號。

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