【问题标题】:Multiple mysql statements on same connection同一连接上的多个mysql语句
【发布时间】:2011-10-22 08:20:48
【问题描述】:

我正在构建一个搜索查询,想知道下面的代码是否有效。基本上我会在第一条语句中设置@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();

【问题讨论】:

  • 为什么不把所有的语句都封装到一个存储过程中?
  • 是的...看起来这是完美的解决方案 :) 是时候将“Bang Your Head Here”标志重新挂在墙上并学习如何创建存储过程了。

标签: php mysql prepared-statement user-variables


【解决方案1】:

如果您有兴趣,我已经找到了 MySQL 存储 procuders 的系列教程。真的很好,很容易学会如何创建自己的!

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

【讨论】:

  • 实际上它需要运行的服务器有mysql4,所以回到方块1 :(
猜你喜欢
  • 1970-01-01
  • 2011-09-18
  • 1970-01-01
  • 2011-12-13
  • 2018-08-30
  • 1970-01-01
  • 2012-03-02
  • 1970-01-01
  • 2016-06-21
相关资源
最近更新 更多