我需要一些關於如何讓我的php腳本不僅看1個字或多個像(John Doe)。目前我的腳本只能從指向表中找到第一個單詞「John」。這是我的腳本:如何在mysql中應用多字搜索
$query = $_GET['query'];
$min_length = 1;
if (strlen($query) >= $min_length) {
$query = htmlspecialchars($query);
$query = mysql_real_escape_string($query);
$raw_results = mysql_query(
"SELECT * FROM filmi WHERE (`title` LIKE '%".$query."%')
OR (`description` LIKE '%".$query."%') OR (`nomer` LIKE '%".$query."%')"
) or die(mysql_error());
if (mysql_num_rows($raw_results) > 0) {
while ($results = mysql_fetch_array($raw_results)) {
echo "
print results
";
}
} else {
echo "No results";
}
} else {
echo "Minimum length is " . $min_length;
}
請[停止使用'mysql_ *'功能](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php)。 [這些擴展](http://php.net/manual/en/migration70.removed-exts-sapis.php)已在PHP 7中刪除。瞭解[編寫](http://en.wikipedia.org/ wiki/Prepared_statement)語句[PDO](http://php.net/manual/en/pdo.prepared-statements.php)和[MySQLi](http://php.net/manual/en/mysqli.quickstart .prepared-statements.php)並考慮使用PDO,[這真的很簡單](http://jayblanchard.net/demystifying_php_pdo.html)。 –
[您的腳本存在SQL注入攻擊風險。](http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) –
我需要使用舊的因爲我的主機提供者尚未升級到php 7. ty的評論 – user2052643