0

I was trying to execute an INSERT query which ensures that only 1 row is inserted and avoid duplicate insertions/ here is my SQL string that i used inside my PHP file:

$sql = "INSERT INTO `users`( `user_name`,`email`,  `password`, `active`) VALUES (:name, :email, :pass, :active) LIMIT 1";

I got this following error:

Calling BeforeException -> string(211) "SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'LIMIT 1' at line 1" 

i think MariaDB Insert command do not use LIMIT syntax. please suggest.Thanks

user5005768Himadree
  • 1,375
  • 3
  • 23
  • 61
  • 2
    Your correct - INSERT doesn't need LIMIT, after all there is only 1 row to insert. Duplicates is another thing which you can update with https://mariadb.com/kb/en/library/insert-on-duplicate-key-update/ – Nigel Ren Jun 04 '18 at 07:39
  • Thanks @NigelRen. As i mentioned, i also want to avoid duplicate insertions. Is there anything else to add on query to do so? or current on is enough? Thanks again – user5005768Himadree Jun 04 '18 at 07:44
  • Just remove `LIMIT 1` – Hackerman Jun 04 '18 at 13:11

0 Answers0