[英]I have a mysql query in my php code that is cut and pasted in two places. How can I get it to be in one place?
我在index.php中有一個查詢,在update.php中有完全相同的查詢。 如何將查詢放在一個位置,以便於管理?
這是我的查詢:
$sets=$_GET["sets"];
$sets = "'" . str_replace(array("'", ","), array("\\'", "','"), $sets) . "'";
// test code
$query = "
SELECT
*
FROM
`cards`
WHERE
`setName` in ($sets)
ORDER BY
`setName` DESC,
LIMIT
500
";
包括header.php
或functions.php
。 然后,在文件中定義查詢。 包括它們之后,您便可以訪問它們。
require 'header.php';
OR
include 'header.php';
function make_query($val)
{
$res = "SELECT * FROM users WHERE id = " . $val;
return $res;
}
創建第三個文件query.php
,將查詢放入此文件中(可能在變量中),並同時包含index.php
和update.php
的文件。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.