2010-11-03 81 views
0

我在使用MySQL数据库的PHP Web应用程序上使用Doctrine。我有一个小问题,我的要求:使用Doctrine生成SQL命令时出现SQL错误PHP

$q = Doctrine_Query::create() 
    ->select('event.EventDate, event.EventId, player.PlayerId, player.FirstName, 
      player.LastName, player.Login, player.Email, 
      event_period.EventPeriodId, event.Type, event.Description, 
      period.StartHour, period.EndHour, player_event_period.Participate, 
      event_period.CourtNumber') 
    ->from('Event event, Player player, Period period') 
    ->leftJoin('player.PlayerEventPeriod player_event_period') 
    ->leftJoin('player_event_period.EventPeriod event_period') 
    ->where('period.PeriodId = event_period.PeriodId') 
    ->andWhere('event.EventId = event_period.EventId'); 

如果我展示什么是生成的MySQL命令,我可以看到

SELECT e.eventid AS e__eventid, e.eventdate AS e__eventdate, e.type AS e__type, e.description AS e__description, p.playerid AS p__playerid, p.firstname AS p__firstname, p.lastname AS p__lastname, p.login AS p__login, p.email AS p__email, p2.periodid AS p2__periodid, p2.starthour AS p2__starthour, p2.endhour AS p2__endhour, p3.playereventperiodid AS p3__playereventperiodid, p3.participate AS p3__participate, e2.eventperiodid AS e2__eventperiodid, e2.courtnumber AS e2__courtnumber 
FROM event e, player p, period p2 
LEFT JOIN player_event_period p3 ON p.playerid = p3.playerid 
LEFT JOIN event_period e2 ON p3.eventperiodid = e2.eventperiodid 
WHERE (
p2.periodid = e2.periodid 
AND e.eventid = e2.eventid 
); 

我得到错误:

#1054 - Unknown column 'p.playerid' in 'on clause' 

这有什么错我的请求 ?

预先感谢您

编辑:

如果这可以帮助你。我添加了创建我的数据库表的脚本。

CREATE TABLE `event` (
    `EventId` int(11) NOT NULL AUTO_INCREMENT, 
    `Type` varchar(100) NOT NULL, 
    `Description` text, 
    `EventDate` datetime NOT NULL, 
    `CreationDate` datetime NOT NULL, 
    `UpdateDate` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00' ON UPDATE CURRENT_TIMESTAMP, 
    PRIMARY KEY (`EventId`) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8; 

CREATE TABLE `event_period` (
    `EventPeriodId` int(11) NOT NULL AUTO_INCREMENT, 
    `PeriodId` int(11) NOT NULL, 
    `EventId` int(11) NOT NULL, 
    `CourtNumber` int(11) NOT NULL, 
    `CreationDate` datetime NOT NULL, 
    `UpdateDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 
    PRIMARY KEY (`EventPeriodId`), 
    KEY `fk_event_period_to_period` (`PeriodId`), 
    KEY `fk_event_period_to_event` (`EventId`) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8; 

CREATE TABLE `period` (
    `PeriodId` int(11) NOT NULL AUTO_INCREMENT, 
    `StartHour` time NOT NULL, 
    `EndHour` time NOT NULL, 
    `CreationDate` datetime NOT NULL, 
    `UpdateDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 
    PRIMARY KEY (`PeriodId`) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8; 

CREATE TABLE `player` (
    `PlayerId` int(11) NOT NULL AUTO_INCREMENT, 
    `Login` varchar(100) NOT NULL, 
    `Password` varchar(100) NOT NULL, 
    `RankId` int(11) NOT NULL DEFAULT '1', 
    `FirstName` varchar(100) NOT NULL, 
    `LastName` varchar(100) NOT NULL, 
    `Email` varchar(100) NOT NULL, 
    `ValidateId` varchar(100) NOT NULL, 
    `InscriptionDate` datetime NOT NULL, 
    `Enable` tinyint(1) NOT NULL, 
    `CreationDate` datetime NOT NULL, 
    `UpdateDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 
    PRIMARY KEY (`PlayerId`), 
    KEY `fk_player_to_rank` (`RankId`) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8; 

CREATE TABLE `player_event_period` (
    `PlayerEventPeriodId` int(11) NOT NULL AUTO_INCREMENT, 
    `PlayerId` int(11) NOT NULL, 
    `EventPeriodId` int(11) NOT NULL, 
    `Participate` tinyint(1) NOT NULL, 
    `CreationDate` datetime NOT NULL, 
    `UpdateDate` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, 
    PRIMARY KEY (`PlayerEventPeriodId`), 
    KEY `fk_player_event_period_to_player` (`PlayerId`), 
    KEY `fk_player_event_period_to_event_period` (`EventPeriodId`) 
) ENGINE=InnoDB DEFAULT CHARSET=utf8; 


ALTER TABLE `event_period` 
    ADD CONSTRAINT `fk_event_period_to_period` FOREIGN KEY (`PeriodId`) REFERENCES `period` (`PeriodId`) ON DELETE CASCADE ON UPDATE CASCADE, 
    ADD CONSTRAINT `fk_event_period_to_event` FOREIGN KEY (`EventId`) REFERENCES `event` (`EventId`) ON DELETE CASCADE ON UPDATE CASCADE; 

ALTER TABLE `player` 
    ADD CONSTRAINT `fk_player_to_rank` FOREIGN KEY (`RankId`) REFERENCES `rank` (`RankId`); 

ALTER TABLE `player_event_period` 
    ADD CONSTRAINT `fk_player_event_period_to_player` FOREIGN KEY (`PlayerId`) REFERENCES `player` (`PlayerId`) ON DELETE CASCADE ON UPDATE CASCADE, 
    ADD CONSTRAINT `fk_player_event_period_to_event_period` FOREIGN KEY (`EventPeriodId`) REFERENCES `event_period` (`EventPeriodId`) ON DELETE CASCADE ON UPDATE CASCADE; 

回答

0

不知道你的车型的外观但所谓的“玩家”你的表已经称为列“playerid”的呢?

这就是mysql所抱怨的。

[编辑]
我认为Doctrine更喜欢列名我小写。 (不记得MySQL是否区分大小写关于列名...)

+0

我已经通过添加生成我的表 – RedPaladin 2010-11-03 12:31:30

+0

我编辑我的答案的结构脚本编辑我的问题... – thaDukeW 2010-11-03 13:52:40

0

MySQL列名的大小写敏感性取决于数据库/架构/表的配置方式,但看起来像您的区分大小写。

你还没有提供实体定义,所以我猜这个问题,但尝试设置列的名称。

例如,对于玩家ID的注释为:

/** 
* @Column(name="PlayerId", type="integer", length=11, nullable=false) 
* @Id 
* GeneratedValue(strategy="AUTO") 
*/ 
protected $PlayerId;