Click here to Skip to main content
15,891,423 members
Articles / All Topics

Doctrine Entity and MySQL Reserved Words

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
19 Jul 2017CPOL 3.6K  
Doctrine entity and MySQL reserved words

Introduction

Recently for an app I’ve been creating, I had to create an ExitForm Doctrine Entity. So I simply created the following code:

PHP
<?php

// src/AppBundle/Entity/ExitForm.php
namespace AppBundle\Entity;

use Doctrine\ORM\Mapping as ORM;

/**
* @ORM\Entity
* @ORM\Table(name="exit")
*/
class ExitForm
{
   ...

Then after that, I ran the standard Symfony commands to generate getters/setters and update the database:

php bin/console doctrine:generate:entities AppBundle/Entity/ExitForm
php bin/console doctrine:schema:update --force

Everything looks fine and ran without any errors.

Checking on the MySQL Database

Then, I went into MySQL and ran the following commands:

SQL
show tables;

It showed all my tables, and it showed “exit” as one of the tables. Then I ran this command:

SQL
describe exit;

It gave me errors. I struggled for awhile trying to figure out what the problem was, but then I figured it out, “exit” is a MySQL Reserved Word. So instead of using that, I changed my code to this:

PHP
/**
* @ORM\Entity
* @ORM\Table(name="exitform")
*/
class ExitForm
{

Everything worked correctly after that. This is just a lesson never to use a Reserved Word.

Tagged: Doctrine, MySQL, Symfony

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer Taft College
United States United States
I’m a software developer. Currently I’m working at Taft College as a Programmer.

Comments and Discussions

 
-- There are no messages in this forum --