2012-01-12 76 views
0

我試圖執行此DQL:學說1.2 - 未知記錄屬性/相關的DQL分量只有1臺envolved

$q = Doctrine_Query::create() 
->select('*'); 
->from('Clientes c'); 
$retorno = $q->execute(); 

我BaseClientes.php:

// Connection Component Binding 
Doctrine_Manager::getInstance()->bindComponent('Clientes', 'padrao'); 

/** 
* BaseClientes 
* 
* This class has been auto-generated by the Doctrine ORM Framework 
* 
* @property integer $pk_clientes 
* @property string $txt_nome 
* @property timestamp $ts_cadastro 
* @property string $txt_diretorio 
* @property Doctrine_Collection $Upload 
* 
* @package ##PACKAGE## 
* @subpackage ##SUBPACKAGE## 
* @author  ##NAME## <##EMAIL##> 
* @version SVN: $Id: Builder.php 7490 2010-03-29 19:53:27Z jwage $ 
*/ 
abstract class BaseClientes extends Doctrine_Record 
{ 
    public function setTableDefinition() 
    { 
     $this->setTableName('clientes'); 
     $this->hasColumn('pk_clientes', 'integer', 4, array(
      'type' => 'integer', 
      'length' => 4, 
      'fixed' => false, 
      'unsigned' => false, 
      'primary' => true, 
      'autoincrement' => true, 
      )); 
     $this->hasColumn('txt_nome', 'string', 255, array(
      'type' => 'string', 
      'length' => 255, 
      'fixed' => false, 
      'unsigned' => false, 
      'primary' => false, 
      'notnull' => true, 
      'autoincrement' => false, 
      )); 
     $this->hasColumn('ts_cadastro', 'timestamp', null, array(
      'type' => 'timestamp', 
      'fixed' => false, 
      'unsigned' => false, 
      'primary' => false, 
      'notnull' => true, 
      'autoincrement' => false, 
      )); 
     $this->hasColumn('txt_diretorio', 'string', 255, array(
      'type' => 'string', 
      'length' => 255, 
      'fixed' => false, 
      'unsigned' => false, 
      'primary' => false, 
      'notnull' => true, 
      'autoincrement' => false, 
      )); 
    } 

    public function setUp() 
    { 
     parent::setUp(); 
     $this->hasMany('Upload', array(
      'local' => 'pk_clientes', 
      'foreign' => 'fk_clientes')); 
    } 
} 

我的表SQL:

CREATE TABLE `organizer`.`clientes` (
    `pk_clientes` int(11) NOT NULL AUTO_INCREMENT, 
    `txt_nome` varchar(255) NOT NULL, 
    `ts_cadastro` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, 
    `txt_diretorio` varchar(255) NOT NULL, 
    PRIMARY KEY (`pk_clientes`) 
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC 

當我執行此DQL,它返回給我:

Fatal error: Uncaught exception 'Doctrine_Record_UnknownPropertyException' with message 'Unknown record property/related component "clientes" on "Clientes"' in 
/var/www/organizer/lib/php/doctrine/lib/Doctrine/Record/Filter/Standard.php:55 Stack trace: #0 /var/www/organizer/lib/php/doctrine/lib/Doctrine/Record.php(1382): 
Doctrine_Record_Filter_Standard->filterGet(Object(Clientes), 'clientes') #1 /var/www/organizer/lib/php/doctrine/lib/Doctrine/Record.php(1337): Doctrine_Record->_get 
('clientes', true) #2 /var/www/organizer/lib/php/doctrine/lib/Doctrine/Access.php(117): Doctrine_Record->get('clientes') #3 /var/www/organizer/lib/php/forger.php 
(387): Doctrine_Access->offsetGet('clientes') #4 /var/www/organizer/app/clientes/model.php(20): forger->Table(Array) #5 /var/www/organizer/app/clientes/controller.php 
(5): require_once('/var/www/organi...') #6 /var/www/organizer/web/index.php(9): require_once('/var/www/organi...') #7 {main} thrown in /var/www/organizer/lib/php/ 
doctrine/lib/Doctrine/Record/Filter/Standard.php on line 55 

我真的不知道發生了什麼,我在我的系統和工作的其他文件中也有這種情況。

請別人幫我....

OBS:對不起我的英語不好,我是巴西人。

+0

嘗試來自DQL機智的SQL查詢ħ'回聲$ Q-> getSqlQuery();' – Thomas 2012-01-12 20:37:35

+0

感謝您的響應托馬斯, 從DQL生成的SQL查詢是: SELECT c.pk_clientes AS c__pk_clientes,c.txt_nome AS c__txt_nome,c.ts_cadastro AS c__ts_cadastro, c.txt_diretorio AS c__txt_diretorio FROM clientes c 我已經在MySQL查詢瀏覽器中執行了這個SQL,它工作... – user1146284 2012-01-13 11:32:09

回答

0

感謝您的答案,但我已經找到了「錯誤」 ......

我需要的是隻在一個陣列中恢復數據,因此我在谷歌搜索,發現這個:

$con = Doctrine_Manager::getInstance()->connection(); 
$res = $con->execute("SELECT * FROM clientes;", array(1)); 
$retorno = $res->fetchAll(); 

這解決了我的問題,因爲我試圖使用的$ Q-返回>的execute()作爲數組...

PS:抱歉拼錯的xD ...呼應產生