Implicit MySQL Join on Update Statement - 0 rows affected - php

I'm trying to get this MySQL code to work, but it's saying 0 rows affected.
UPDATE assessments, assessment_types
SET assessments.assessment_type_id = assessment_types.id
WHERE (assessment_types.description = "Skills Assessment" AND assessments.id = 2);
Basically I have assessment_types with id and description column, and I just have the id in the assessments.assessment_type_id
I need to update the id.
I searched and couldn't find quite what I need for this.
Thanks!
Table Data:
assessment_types
id description
1 Knowledge Assessment
2 Skill Assessment
3 Personal Information
4 Natural Skills
Table Structure:
--
-- Table structure for table `assessments`
--
CREATE TABLE IF NOT EXISTS `assessments` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(255) COLLATE utf8_bin NOT NULL,
`acronym` varchar(255) COLLATE utf8_bin NOT NULL,
`assessment_type_id` int(11) NOT NULL,
`language_id` int(11) NOT NULL,
`date_created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`date_updated` date NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`),
KEY `assessment_type_id` (`assessment_type_id`),
KEY `language_id` (`language_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=2385 ;
--
-- Table structure for table `assessment_types`
--
CREATE TABLE IF NOT EXISTS `assessment_types` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`description` varchar(255) CHARACTER SET latin1 NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `id` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin AUTO_INCREMENT=7 ;

You can try doing an explicit join of the two tables in your UPDATE statement:
UPDATE assessments a
INNER JOIN assessment_types at
ON a.assessment_type_id = at.id
SET a.assessment_type_id = at.id
WHERE (at.description = "Skills Assessment" AND a.id = 2);

Related

How to select from relational database?

I am starting to learn how databases work and I have always had all my data in one table. I am looking over an open-source project which I would like to create an interface for and the database structure is too complicated for me to understand.
I am sure it has a relational database structure (if I have learned properly). This is what the database structure looks like:
-- Table structure for table `databasechangelog`
--
CREATE TABLE IF NOT EXISTS `databasechangelog` (
`ID` varchar(255) NOT NULL,
`AUTHOR` varchar(255) NOT NULL,
`FILENAME` varchar(255) NOT NULL,
`DATEEXECUTED` datetime NOT NULL,
`ORDEREXECUTED` int(11) NOT NULL,
`EXECTYPE` varchar(10) NOT NULL,
`MD5SUM` varchar(35) DEFAULT NULL,
`DESCRIPTION` varchar(255) DEFAULT NULL,
`COMMENTS` varchar(255) DEFAULT NULL,
`TAG` varchar(255) DEFAULT NULL,
`LIQUIBASE` varchar(20) DEFAULT NULL,
`CONTEXTS` varchar(255) DEFAULT NULL,
`LABELS` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
-- Table structure for table `databasechangeloglock`
--
CREATE TABLE IF NOT EXISTS `databasechangeloglock` (
`ID` int(11) NOT NULL,
`LOCKED` bit(1) NOT NULL,
`LOCKGRANTED` datetime DEFAULT NULL,
`LOCKEDBY` varchar(255) DEFAULT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
-- Table structure for table `devices`
--
CREATE TABLE IF NOT EXISTS `devices` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(128) NOT NULL,
`uniqueid` varchar(128) NOT NULL,
`status` varchar(128) DEFAULT NULL,
`lastupdate` timestamp NULL DEFAULT NULL,
`positionid` int(11) DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `uk_device_uniqueid` (`uniqueid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
-- --------------------------------------------------------
-- Table structure for table `positions`
--
CREATE TABLE IF NOT EXISTS `positions` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`protocol` varchar(128) DEFAULT NULL,
`deviceid` int(11) NOT NULL,
`servertime` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`devicetime` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`fixtime` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
`valid` bit(1) NOT NULL,
`latitude` double NOT NULL,
`longitude` double NOT NULL,
`altitude` float NOT NULL,
`speed` float NOT NULL,
`course` float NOT NULL,
`address` varchar(512) DEFAULT NULL,
`attributes` varchar(4096) NOT NULL,
PRIMARY KEY (`id`),
KEY `position_deviceid_fixtime` (`deviceid`,`fixtime`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=145 ;
-- --------------------------------------------------------
-- Table structure for table `server`
--
CREATE TABLE IF NOT EXISTS `server` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`registration` bit(1) NOT NULL DEFAULT b'1',
`latitude` double NOT NULL DEFAULT '0',
`longitude` double NOT NULL DEFAULT '0',
`zoom` int(11) NOT NULL DEFAULT '0',
`map` varchar(128) DEFAULT NULL,
`language` varchar(128) DEFAULT NULL,
`distanceunit` varchar(128) DEFAULT NULL,
`speedunit` varchar(128) DEFAULT NULL,
`bingkey` varchar(128) DEFAULT NULL,
`mapurl` varchar(128) DEFAULT NULL,
`readonly` bit(1) NOT NULL DEFAULT b'0',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;
-- --------------------------------------------------------
-- Table structure for table `users`
--
CREATE TABLE IF NOT EXISTS `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(128) NOT NULL,
`email` varchar(128) NOT NULL,
`hashedpassword` varchar(128) NOT NULL,
`salt` varchar(128) NOT NULL,
`readonly` bit(1) NOT NULL DEFAULT b'0',
`admin` bit(1) NOT NULL DEFAULT b'0',
`map` varchar(128) NOT NULL DEFAULT 'osm',
`language` varchar(128) NOT NULL DEFAULT 'en',
`distanceunit` varchar(128) NOT NULL DEFAULT 'km',
`speedunit` varchar(128) NOT NULL DEFAULT 'kmh',
`latitude` double NOT NULL DEFAULT '0',
`longitude` double NOT NULL DEFAULT '0',
`zoom` int(11) NOT NULL DEFAULT '0',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_user_email` (`email`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;
-- --------------------------------------------------------
-- Table structure for table `user_device`
--
CREATE TABLE IF NOT EXISTS `user_device` (
`userid` int(11) NOT NULL,
`deviceid` int(11) NOT NULL,
KEY `fk_user_device_deviceid` (`deviceid`),
KEY `user_device_user_id` (`userid`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
--
-- Constraints for dumped tables
--
--
-- Constraints for table `positions`
--
ALTER TABLE `positions`
ADD CONSTRAINT `fk_position_deviceid` FOREIGN KEY (`deviceid`) REFERENCES `devices` (`id`) ON DELETE CASCADE;
--
-- Constraints for table `user_device`
--
ALTER TABLE `user_device`
ADD CONSTRAINT `fk_user_device_deviceid` FOREIGN KEY (`deviceid`) REFERENCES `devices` (`id`) ON DELETE CASCADE,
ADD CONSTRAINT `fk_user_device_userid` FOREIGN KEY (`userid`) REFERENCES `users` (`id`) ON DELETE CASCADE;
When a user registers, it adds an entry to the "users" table and the user gets an id.
Then when the user adds a device, the user_device table looks like this:
And the devices table looks like this:
This is a GPS tracking software, so each device then posts it's position in the "positions" table which looks like this:
So, if a user logs in, how do I query the positions table and get all info from all devices of that user? I am assuming I would need to join the tables but I don't know how to do that. Any help would be greatly appreciated.
Let's build it incrementally. First, what is the actual data you want?
query the positions table
Ok, start with that:
SELECT
*
FROM
positions
Now how do you want to further filter that data?
from all devices of that user
Ok, so we need to relate this table (positions) through devices and to the user. So ultimately we'll need a WHERE clause like this:
WHERE
userid = ?
But positions doesn't have a userid, so let's walk through joining some tables until we have one. positions does have a deviceid, so we can join that:
SELECT
*
FROM
positions
INNER JOIN devices
ON positions.deviceid = devices.id
We still don't have a userid, though. And devices itself doesn't reference anything to further help us. But there's a table which does reference devices, user_device. Let's join that:
SELECT
*
FROM
positions
INNER JOIN devices
ON positions.deviceid = devices.id
INNER JOIN user_device
ON devices.id = user_device.deviceid
You'll see that we're getting a lot of data now. But you'll also see that we're now getting a userid column, so we can finally add our WHERE clause:
SELECT
*
FROM
positions
INNER JOIN devices
ON positions.deviceid = devices.id
INNER JOIN user_device
ON devices.id = user_device.deviceid
WHERE
userid = ?
At this point we should be getting all of the unique positions from any device related to that user. You can get just the position data by replacing SELECT * with SELECT positions.*, or you can explicitly define which columns from which tables you want to select.
it would appear from your notes that you know when the user logs in which device he has. if this is correct, you should not need a join. Just do a select on the positions table where the positions.deviceid = the login device.

Querying SQL multiple tables

I have a sql database with the following tables
Book Table
CREATE TABLE IF NOT EXISTS `books` (
`book_id` varchar(8) NOT NULL DEFAULT '',
`book_title` varchar(100) DEFAULT NULL,
`author1` varchar(20) NOT NULL,
`author2` varchar(20) DEFAULT NULL,
`publisher` varchar(20) NOT NULL,
`pub_year` year(4) NOT NULL,
`mod_id` varchar(8) NOT NULL,
`courseID` varchar(8) NOT NULL,
PRIMARY KEY (`book_id`),
KEY `id` (`book_id`),
KEY `book_id` (`book_id`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Courses Table
CREATE TABLE IF NOT EXISTS `courses` (
`courseID` varchar(8) NOT NULL,
`course_title` varchar(255) CHARACTER SET ascii NOT NULL,
`Entry_Year` int(1) NOT NULL,
`Duration` int(1) NOT NULL,
PRIMARY KEY (`courseID`),
KEY `courseID` (`courseID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Modules Table
CREATE TABLE IF NOT EXISTS `modules` (
`mod_id` varchar(8) NOT NULL,
`mod_title` varchar(255) NOT NULL,
`description` varchar(255) NOT NULL,
PRIMARY KEY (`mod_id`),
KEY `mod_title` (`mod_title`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
Module Course Table
CREATE TABLE IF NOT EXISTS `mod_course` (
`ID` int(11) NOT NULL AUTO_INCREMENT,
`module` varchar(8) NOT NULL,
`course` varchar(8) NOT NULL,
PRIMARY KEY (`ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=31 ;
I would like to query the database to show all book details of a course. A course has many modules and modules have many books. I have tried the following query but I think there is a problem with my tables as well. (FYI 'BIT' is the id of a course that is in the module course table)
SELECT b.book_id, b.book_title, b.author1, b.author2, b.publisher, b.pub_year, b.mod_id, mc.course
FROM books b
JOIN mod_course mc
WHERE mc.course = 'BIT'
I have had a deeper look at this and offer the following suggestion which includes changes to the data model also. This solution will also allow you to have the same book used for several modules (if required in the future). Also note the new table mod_books
The full code for this (including the query) is below... hope its ok
CREATE TABLE IF NOT EXISTS books
(book_id varchar(8) NOT NULL DEFAULT '',
book_title varchar(100) DEFAULT NULL,
author1 varchar(20) NOT NULL,
author2 varchar(20) DEFAULT NULL,
publisher varchar(20) NOT NULL,
pub_year year(4) NOT NULL,
PRIMARY KEY (book_id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE IF NOT EXISTS courses
(course_ID varchar(8) NOT NULL,
course_title varchar(255) CHARACTER SET ascii NOT NULL,
Entry_Year int(1) NOT NULL,
Duration int(1) NOT NULL,
PRIMARY KEY (course_ID)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE IF NOT EXISTS modules
(mod_id varchar(8) NOT NULL,
mod_title varchar(255) NOT NULL,
description varchar(255) NOT NULL,
PRIMARY KEY (mod_id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE IF NOT EXISTS mod_books
(mod_id varchar(8) NOT NULL,
book_id varchar(8) NOT NULL,
PRIMARY KEY (mod_id,book_id),
FOREIGN KEY (mod_id) REFERENCES modules (mod_id),
FOREIGN KEY (book_id) REFERENCES books (book_id)
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE IF NOT EXISTS mod_course
(ID int(11) NOT NULL AUTO_INCREMENT,
mod_id varchar(8) NOT NULL,
course_ID varchar(8) NOT NULL,
PRIMARY KEY (ID),
FOREIGN KEY (mod_id) REFERENCES modules (mod_id),
FOREIGN KEY (course_ID) REFERENCES courses (course_ID)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=31 ;
and the query would be
SELECT b.*
FROM mod_course mc
INNER JOIN mod_books mb
ON mb.mod_id = mc.mod_id
INNER JOIN books b
ON b.book_id = mb.book_id
WHERE mc.course_id = 'BIT'
based on the stated relationship course->module->books, you should drop the courseid column from the books table. the modid that you have is all you need.
the problem with your query is the missing join condition.
below the JOIN mod_course mc line you should add
ON mc.module = b.mod_id
After the keyword Join it should be ON not WHERE
SELECT B.*, MC.COURSE
FROM MODULECOURSE AS MC
INNER JOIN COURSES AS C
ON C.COURSE_TITLE = MC.COURSE
INNER JOIN BOOKS AS B
ON B.COURSEID= C.COURSEID

Red bean php R::getAll doesn't return any records

Here is database structure, generated with red bean php:
CREATE TABLE `attrib` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`type` tinyint(3) unsigned DEFAULT NULL,
`value` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=10 ;
CREATE TABLE `attrib_photo` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`attrib_id` int(11) unsigned DEFAULT NULL,
`photo_id` int(11) unsigned DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `UQ_e472845bf988796e2d3eceb91e2745b95f3aa534` (`attrib_id`,`photo_id`),
KEY `index_for_attrib_photo_attrib_id` (`attrib_id`),
KEY `index_for_attrib_photo_photo_id` (`photo_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=19 ;
CREATE TABLE `photo` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`filepath` varchar(255) COLLATE utf8_unicode_ci DEFAULT NULL,
`date` set('1') COLLATE utf8_unicode_ci DEFAULT NULL,
`iscolored` tinyint(3) unsigned DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=4 ;
ALTER TABLE `attrib_photo`
ADD CONSTRAINT `attrib_photo_ibfk_1` FOREIGN KEY (`attrib_id`) REFERENCES `attrib` (`id`) ON DELETE CASCADE,
ADD CONSTRAINT `attrib_photo_ibfk_2` FOREIGN KEY (`photo_id`) REFERENCES `photo` (`id`) ON DELETE CASCADE;
I'm making manually constructed query:
output of R::debug(); R::getAll($sql);
select filepath
from photo
inner join attrib as attrib4 on attrib4.type = 4 and attrib4.value in ("Dmitry")
inner join attrib_photo as attrib_photo4 on attrib_photo4.attrib_id = attrib4.id and attrib_photo4.photo_id = photo.id WHERE 1=1 LIMIT 0,25
Array ( )
resultset: 0 rows
[]
The result set is empty, but the base contains records, which fall under requirements, and running sql manually in phpMyAdmin shows them.
What's the problem with query, are there any additional debug info I can deal with to solve the problem? Thanks.
Update:
A little detail was missing, in original query I used unicode string for photo attribute search. After some investigations I found that php code works correctly and wrong encoding conversion happens on mysql side. Decision was to change collation of whole database to utf8_unicode_ci. Thanks for attention, and sorry for missing info in question.

MySQL JOIN query more tables and return more result in one select

I would question, sorry my bad english :(
I have multiple tables
CREATE TABLE `user` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`username` varchar(50) COLLATE utf8_slovak_ci NOT NULL,
`password` varchar(200) COLLATE utf8_slovak_ci NOT NULL,
`status` tinyint(1) NOT NULL,
PRIMARY KEY (`id`,`username`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_slovak_ci;
CREATE TABLE `user_acl` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`id_user` int(11) unsigned NOT NULL,
`group` smallint(5) unsigned NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COLLATE=utf8_slovak_ci;
CREATE TABLE `user_profil` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`email` varchar(100) COLLATE utf8_slovak_ci NOT NULL,
`fullname` varchar(100) COLLATE utf8_slovak_ci NOT NULL,
`profil` text COLLATE utf8_slovak_ci NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8 COLLATE=utf8_slovak_ci;
Query:
SELECT user.*, prf.*, acl.*
FROM (SELECT * FROM user LIMIT 1) AS user
LEFT JOIN user_acl AS acl ON (acl.id_user = user.id)
INNER JOIN user_profil AS prf ON (user.id = prf.id)
I have table user, user_acl, user_profil
table user and user_profil are indexed under id what is the common key
Table user_acl have id_usercommon key with table user (id) in the table but user_acl There are more rows for the table user and I need all rows from a table user_acl in one query.
You can get MySQL to combine values from multiple rows into one row with GROUP_CONCAT:
SELECT user.*, prf.*, GROUP_CONCAT(acl.id), GROUP_CONCAT(acl.group)
FROM user
LEFT JOIN user_acl AS acl ON (acl.id_user = user.id)
INNER JOIN user_profil AS prf ON (user.id = prf.id)
GROUP BY user.id;
You can't. You have to separate query, if you need more than one acl row to one user row.
[EDIT]: But if you need to to it with one query then you should use somekindof bitwise operations. http://codingrecipes.com/how-to-write-a-permission-system-using-bits-and-bitwise-operations-in-php

SQL error when generated SQL command with Doctrine PHP

I use Doctrine on my PHP web application with a MySQL database. I have a little problem with my request :
$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');
if I show what is the generated MySQL command, I can see
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
);
I get error :
#1054 - Unknown column 'p.playerid' in 'on clause'
What's wrong with my request ?
Thank you in advance
EDIT:
If that could help you. I have add the script that creates my database tables.
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;
Not sure how your models look but do your table called "player" have a column called "playerid" in it?
That's what mysql is complaining about.
[Edit]
I think that Doctrine prefers column names i lowercase.
(Can't remember if MySQL is case-sensitive regarding column names...)
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;

Categories