0

I'm building a search query and was wondering if the code below would be valid. Basically I would set the @keywords variable in the first statement and then use it in the 2nd statement. It seems to be working just fine but I'm not sure if it's a good procedure. Any ideas? :)

The point would be that the query would be more complex and @keyword would show up a number of times.

$list_images_kw = $mysqli_link->prepare("SET @keyword=?;");
$list_images_kw->bind_param('s', $search_string);
$list_images_kw->execute();
$list_images_kw->close();                 
$list_images = $mysqli_link->prepare(
    "SELECT * FROM `images` WHERE UCASE(`images`.img_title) REGEXP @keyword" ); 
$list_images->execute();
$list_images->close();
imm
  • 5,837
  • 1
  • 26
  • 32
Alex
  • 1
  • 3
    Why you don't enclosing all that statements into a stored procedure ? – KodeFor.Me Oct 22 '11 at 08:24
  • Yep... looks like that is the perfect solution :) Time to put the "Bang Your Head Here" sign back on the wall and learn how to create stored procedures. – Alex Oct 22 '11 at 09:36

1 Answers1

0

If you are interested I have found the series of tutorials for MySQL Stored procuders. Is realy good and very simple to learn how to create your own!

http://www.mysqltutorial.org/mysql-stored-procedure-tutorial.aspx

Avag Sargsyan
  • 2,437
  • 3
  • 28
  • 41
KodeFor.Me
  • 13,069
  • 27
  • 98
  • 166