Error inserting data into a table using doctrine and mssql
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
add a comment |
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
add a comment |
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
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
php sql sql-server symfony doctrine-orm
edited Nov 21 '18 at 17:48
Nestor
asked Nov 21 '18 at 16:51
NestorNestor
259
259
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
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.
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
add a comment |
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.
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
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
add a comment |
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.
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
add a comment |
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.
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.
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
add a comment |
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
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
edited Nov 21 '18 at 18:59
answered Nov 21 '18 at 18:39
NestorNestor
259
259
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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