I'm writing stored procedures for the first time, and it's not working. The trouble is I can't see a reason for it not to work.
I'm running it through phpmyadmin 2.8.2.4. My MySQL version is 5.1. Here is the first part of the query:
create procedure under_user_type (in original_post int, out user_type int, out user_id longtext)
begin
if exists (
select *
from wp_postmeta as pm
where pm.post_id = original_post
and pm.meta_key = '_tdomf_original_poster_id'
) then
set user_type = 0;
select pm.meta_value
into user_id
from wp_postmeta as pm
where pm.post_id = original_post
and pm.meta_key = '_tdomf_original_poster_id';
elseif exists ( ...
I get the 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 9
Line 9 corresponds to that first select statement in the if exists ( ... ) then
portion.
update:
I get the same error if I use:
create procedure under_user_type (in original_post int, out user_type int, out user_id longtext)
begin
if 1=1 then begin
set user_type = 0;
select pm.meta_value
into user_id
from wp_postmeta as pm
where pm.post_id = original_post
and pm.meta_key = '_tdomf_original_poster_id';
end;
Update Again:
Running the examples on this MySQL documentation page also gives me the "check your syntax near ''" error. I tried removing all tabs from the query but that did nothing.
Update a third time:
I can run this query:
create procedure blah()
begin
end;
but not this query:
create procedure blah2()
begin
if 1=1 then
begin
end;
end if;
end;
as I get the same error.