MySQL prepared stmt issue -


i've following simple table structures , prepared statement:

create table junk1(name varchar(10), state varchar(10)); create table junk2(state varchar(100)); insert junk2(state)values("state '%tex%'"),("state '%neb%'"),("state '%was%'"); insert junk1(name, state) values ('asa', 'texas'), ('dff', 'washing'), ('fgfgf', 'oklahoma'), ('bbb', 'nevada'), ('hhh', 'texas'), ('jjj', 'nebraska'); set @va = ''; select group_concat(state separator ' or ') @va junk2; prepare stmt1 'select * junk1 ?'; execute stmt1 using @va; deallocate prepare stmt1; 

i'm not getting results expected. no results. i'm doing wrong here?

you can't use syntax elements parameters in prepared statement, i.e. can't pass entire clause parameter, values.

you may want concatenate clause instead:

select group_concat(state separator '" or "') @va junk2; set @clause = concat('select * junk1 "', @va, '"'); prepare stmt1 @clause; 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -