0

我在带有 MySQL 数据库的 PHP Web 应用程序上使用 Doctrine。我的请求有一点问题:

$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;
4

2 回答 2

0

不确定您的模型看起来如何,但您的名为“player”的表中是否有一个名为“playerid”的列?

这就是mysql所抱怨的。

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

于 2010-11-03T12:27:07.147 回答
0

Case sensitivity of MySQL column names depends on how the database/schema/tables are configured, but it looks like yours are case sensitive.

You haven't provided the entity definitions so I'm guessing at the issue, but try setting the name of the column.

For example for player id the annotation would be:

/**
 * @Column(name="PlayerId", type="integer", length=11, nullable=false)
 * @Id
 * GeneratedValue(strategy="AUTO")
 */
protected $PlayerId;
于 2013-08-09T09:27:51.830 回答