Error inserting data into a table using doctrine and mssql












0














I'm trying to insert data into a created database with the corresponding table this way (Symfony4):



    /**
* @Route("/admin/user/new", name="admin_add_new_user")
*/
public function new_user(EntityManagerInterface $em)
{
$user = new User();
$user->setUsername('felipito')
->setPassword('canelo123')
->setEmail('fpcanelo@ati.cu');

$em->persist($user);
$em->flush();

return $this->render('admin/index.html.twig', [
'controller_name' => 'AdminController',
'brand' => 'brand',
'msg' => sprintf(
'New user dude: id #%d user %s', $user->getId(), $user->getUsername()
)
]);
}


Once I open the url it throws the following:



An exception occurred while executing 'INSERT INTO user (username, roles, password, email) VALUES (?, ?, ?, ?)' with params ["felipito", "", "canelo123", "fpcanelo@ati.cu"]:

SQLSTATE [42000, 156]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Incorrect syntax near the keyword 'user'.
SQLSTATE [42000, 8180]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Statement(s) could not be prepared.


Maybe the problem is related with this problem I had yesterday










share|improve this question





























    0














    I'm trying to insert data into a created database with the corresponding table this way (Symfony4):



        /**
    * @Route("/admin/user/new", name="admin_add_new_user")
    */
    public function new_user(EntityManagerInterface $em)
    {
    $user = new User();
    $user->setUsername('felipito')
    ->setPassword('canelo123')
    ->setEmail('fpcanelo@ati.cu');

    $em->persist($user);
    $em->flush();

    return $this->render('admin/index.html.twig', [
    'controller_name' => 'AdminController',
    'brand' => 'brand',
    'msg' => sprintf(
    'New user dude: id #%d user %s', $user->getId(), $user->getUsername()
    )
    ]);
    }


    Once I open the url it throws the following:



    An exception occurred while executing 'INSERT INTO user (username, roles, password, email) VALUES (?, ?, ?, ?)' with params ["felipito", "", "canelo123", "fpcanelo@ati.cu"]:

    SQLSTATE [42000, 156]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Incorrect syntax near the keyword 'user'.
    SQLSTATE [42000, 8180]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Statement(s) could not be prepared.


    Maybe the problem is related with this problem I had yesterday










    share|improve this question



























      0












      0








      0







      I'm trying to insert data into a created database with the corresponding table this way (Symfony4):



          /**
      * @Route("/admin/user/new", name="admin_add_new_user")
      */
      public function new_user(EntityManagerInterface $em)
      {
      $user = new User();
      $user->setUsername('felipito')
      ->setPassword('canelo123')
      ->setEmail('fpcanelo@ati.cu');

      $em->persist($user);
      $em->flush();

      return $this->render('admin/index.html.twig', [
      'controller_name' => 'AdminController',
      'brand' => 'brand',
      'msg' => sprintf(
      'New user dude: id #%d user %s', $user->getId(), $user->getUsername()
      )
      ]);
      }


      Once I open the url it throws the following:



      An exception occurred while executing 'INSERT INTO user (username, roles, password, email) VALUES (?, ?, ?, ?)' with params ["felipito", "", "canelo123", "fpcanelo@ati.cu"]:

      SQLSTATE [42000, 156]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Incorrect syntax near the keyword 'user'.
      SQLSTATE [42000, 8180]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Statement(s) could not be prepared.


      Maybe the problem is related with this problem I had yesterday










      share|improve this question















      I'm trying to insert data into a created database with the corresponding table this way (Symfony4):



          /**
      * @Route("/admin/user/new", name="admin_add_new_user")
      */
      public function new_user(EntityManagerInterface $em)
      {
      $user = new User();
      $user->setUsername('felipito')
      ->setPassword('canelo123')
      ->setEmail('fpcanelo@ati.cu');

      $em->persist($user);
      $em->flush();

      return $this->render('admin/index.html.twig', [
      'controller_name' => 'AdminController',
      'brand' => 'brand',
      'msg' => sprintf(
      'New user dude: id #%d user %s', $user->getId(), $user->getUsername()
      )
      ]);
      }


      Once I open the url it throws the following:



      An exception occurred while executing 'INSERT INTO user (username, roles, password, email) VALUES (?, ?, ?, ?)' with params ["felipito", "", "canelo123", "fpcanelo@ati.cu"]:

      SQLSTATE [42000, 156]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Incorrect syntax near the keyword 'user'.
      SQLSTATE [42000, 8180]: [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Statement(s) could not be prepared.


      Maybe the problem is related with this problem I had yesterday







      php sql sql-server symfony doctrine-orm






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 21 '18 at 17:48







      Nestor

















      asked Nov 21 '18 at 16:51









      NestorNestor

      259




      259
























          2 Answers
          2






          active

          oldest

          votes


















          0














          looks like user is a reserved word in MySQL.
          Update your User entity @ORMTable annotation like this.



           use DoctrineORMMapping as ORM;

          /**
          * @ORMEntity
          * @ORMTable(name="`user`")
          */
          class User extends BaseUser
          {
          // [....]
          }


          Note the name of the table is using single quotes.






          share|improve this answer

















          • 1




            Hey @rodmar-zavala, besides I'm using sql server, you were right, it seems 'user' is a reserved word in sql server aswell, so I refactored the whole thing again and it worked, thanks
            – Nestor
            Nov 21 '18 at 18:33










          • @Nestor Great! do you mind mark the answer as useful? I am new and trying to gain reputation! Thanks!
            – Rodmar Zavala
            Nov 21 '18 at 18:40





















          1














          Like @rodmar-zavala answered, the problem is I was using a reserved word in sql server. It also applies to this error I got when making the migration on doctrine.



          So I refactored the class name and it worked OK.






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53416953%2ferror-inserting-data-into-a-table-using-doctrine-and-mssql%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            looks like user is a reserved word in MySQL.
            Update your User entity @ORMTable annotation like this.



             use DoctrineORMMapping as ORM;

            /**
            * @ORMEntity
            * @ORMTable(name="`user`")
            */
            class User extends BaseUser
            {
            // [....]
            }


            Note the name of the table is using single quotes.






            share|improve this answer

















            • 1




              Hey @rodmar-zavala, besides I'm using sql server, you were right, it seems 'user' is a reserved word in sql server aswell, so I refactored the whole thing again and it worked, thanks
              – Nestor
              Nov 21 '18 at 18:33










            • @Nestor Great! do you mind mark the answer as useful? I am new and trying to gain reputation! Thanks!
              – Rodmar Zavala
              Nov 21 '18 at 18:40


















            0














            looks like user is a reserved word in MySQL.
            Update your User entity @ORMTable annotation like this.



             use DoctrineORMMapping as ORM;

            /**
            * @ORMEntity
            * @ORMTable(name="`user`")
            */
            class User extends BaseUser
            {
            // [....]
            }


            Note the name of the table is using single quotes.






            share|improve this answer

















            • 1




              Hey @rodmar-zavala, besides I'm using sql server, you were right, it seems 'user' is a reserved word in sql server aswell, so I refactored the whole thing again and it worked, thanks
              – Nestor
              Nov 21 '18 at 18:33










            • @Nestor Great! do you mind mark the answer as useful? I am new and trying to gain reputation! Thanks!
              – Rodmar Zavala
              Nov 21 '18 at 18:40
















            0












            0








            0






            looks like user is a reserved word in MySQL.
            Update your User entity @ORMTable annotation like this.



             use DoctrineORMMapping as ORM;

            /**
            * @ORMEntity
            * @ORMTable(name="`user`")
            */
            class User extends BaseUser
            {
            // [....]
            }


            Note the name of the table is using single quotes.






            share|improve this answer












            looks like user is a reserved word in MySQL.
            Update your User entity @ORMTable annotation like this.



             use DoctrineORMMapping as ORM;

            /**
            * @ORMEntity
            * @ORMTable(name="`user`")
            */
            class User extends BaseUser
            {
            // [....]
            }


            Note the name of the table is using single quotes.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 21 '18 at 18:00









            Rodmar ZavalaRodmar Zavala

            826




            826








            • 1




              Hey @rodmar-zavala, besides I'm using sql server, you were right, it seems 'user' is a reserved word in sql server aswell, so I refactored the whole thing again and it worked, thanks
              – Nestor
              Nov 21 '18 at 18:33










            • @Nestor Great! do you mind mark the answer as useful? I am new and trying to gain reputation! Thanks!
              – Rodmar Zavala
              Nov 21 '18 at 18:40
















            • 1




              Hey @rodmar-zavala, besides I'm using sql server, you were right, it seems 'user' is a reserved word in sql server aswell, so I refactored the whole thing again and it worked, thanks
              – Nestor
              Nov 21 '18 at 18:33










            • @Nestor Great! do you mind mark the answer as useful? I am new and trying to gain reputation! Thanks!
              – Rodmar Zavala
              Nov 21 '18 at 18:40










            1




            1




            Hey @rodmar-zavala, besides I'm using sql server, you were right, it seems 'user' is a reserved word in sql server aswell, so I refactored the whole thing again and it worked, thanks
            – Nestor
            Nov 21 '18 at 18:33




            Hey @rodmar-zavala, besides I'm using sql server, you were right, it seems 'user' is a reserved word in sql server aswell, so I refactored the whole thing again and it worked, thanks
            – Nestor
            Nov 21 '18 at 18:33












            @Nestor Great! do you mind mark the answer as useful? I am new and trying to gain reputation! Thanks!
            – Rodmar Zavala
            Nov 21 '18 at 18:40






            @Nestor Great! do you mind mark the answer as useful? I am new and trying to gain reputation! Thanks!
            – Rodmar Zavala
            Nov 21 '18 at 18:40















            1














            Like @rodmar-zavala answered, the problem is I was using a reserved word in sql server. It also applies to this error I got when making the migration on doctrine.



            So I refactored the class name and it worked OK.






            share|improve this answer




























              1














              Like @rodmar-zavala answered, the problem is I was using a reserved word in sql server. It also applies to this error I got when making the migration on doctrine.



              So I refactored the class name and it worked OK.






              share|improve this answer


























                1












                1








                1






                Like @rodmar-zavala answered, the problem is I was using a reserved word in sql server. It also applies to this error I got when making the migration on doctrine.



                So I refactored the class name and it worked OK.






                share|improve this answer














                Like @rodmar-zavala answered, the problem is I was using a reserved word in sql server. It also applies to this error I got when making the migration on doctrine.



                So I refactored the class name and it worked OK.







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 21 '18 at 18:59

























                answered Nov 21 '18 at 18:39









                NestorNestor

                259




                259






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53416953%2ferror-inserting-data-into-a-table-using-doctrine-and-mssql%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    404 Error Contact Form 7 ajax form submitting

                    How to know if a Active Directory user can login interactively

                    Refactoring coordinates for Minecraft Pi buildings written in Python