同一连接上的多个 mysql 语句
我正在构建一个搜索查询,想知道下面的代码是否有效。基本上我会在第一个语句中设置 @keywords 变量,然后在第二个语句中使用它。它似乎工作得很好,但我不确定这是否是一个好的程序。有什么想法吗? :)
问题是查询会更加复杂,并且 @keyword 会出现多次。
$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();
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();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您有兴趣,我找到了 MySQL 存储过程的系列教程。真的很好,而且非常简单,可以学习如何创建自己的!
http://www.mysqltutorial.org/mysql-stored-procedure-tutorial.aspx
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