0

I would like to create a stored procedure in PHP MySQL via PHPMyAdmin. When I put this on as a SQL command:

CREATE PROCEDURE getBanks() 
BEGIN
select * from cp_banks; END

I receive the following error:

There seems to be an error in your SQL query. The MySQL server error output below, if there is any, may also help you in diagnosing the problem

ERROR: Unknown Punctuation String @ 1 STR: // SQL: // CREATE PROCEDURE getBanks() BEGIN select * from cp_banks;// CREATE PROCEDURE getBanks() BEGIN select * from cp_banks;// CREATE PROCEDURE getBanks() BEGIN select * from cp_banks;

MySQL said:

1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '//

CREATE PROCEDURE getBanks() BEGIN select * from cp_banks' at line 1

Please tell me where the error comes from.

War10ck
  • 12,387
  • 7
  • 41
  • 54
user3668857
  • 11
  • 1
  • 4
  • 1
    The error message complains about `//`, but I don't see that in your procedure. I think you're not showing us everything. – Barmar May 27 '14 at 16:43
  • possible duplicate of [How to write a stored procedure using phpmyadmin and how to use it through php?](http://stackoverflow.com/questions/2846516/how-to-write-a-stored-procedure-using-phpmyadmin-and-how-to-use-it-through-php) – Jay Blanchard May 27 '14 at 16:44
  • 1
    I presume you're using `//` as a delimiter? Have you defined this anywhere? I believe there is an input box where you can specify the delimiter in PHPMyAdmin near the bottom of the SQL Command window. Make sure you set the delimiter to `//` there. – War10ck May 27 '14 at 16:44
  • It looks like you haven't defined the delimiter. – Jay Blanchard May 27 '14 at 16:45

1 Answers1

0

You need to define the delimiter or call it before creating your procedure.

delimiter //
CREATE PROCEDURE getBanks() 
BEGIN
    select * from cp_banks;
END//

Since you are using phpmyadmin, you should remove the delimiter line and set it in the GUI; https://i.stack.imgur.com/Jfb8q.png

Sefam
  • 1,712
  • 2
  • 23
  • 40
  • Now its give following error - "#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '//' at line 4" – user3668857 May 27 '14 at 16:48
  • 1
    @Sefam You're on the right track. I believe PHPMyAdmin has a delimiter input box though right below the SQL Command window. You should leave the SQL statement as is and simply define the delimiter in the specified input box. – War10ck May 27 '14 at 16:50
  • Since you are using phpmyadmin, you should go in the sql tab and set the "Delimiter" field to //. Edit: Didn't see War10ck's response, pretty much what he said. remove the delimiter line and set it directly through the GUI; as shown here http://i.stack.imgur.com/Jfb8q.png – Sefam May 27 '14 at 16:50