您好,我在网站上搜索时遇到此错误。
致命错误:未捕获错误:在/home/u321547826/public_html/search.php:14中调用未定义函数mysql_connect()堆栈跟踪:#h {main}在/home/u321547826/public_html/search.php中引发第14行
我正在使用此代码,任何人都可以提供帮助吗?
<?php
$button = $_GET['submit'];
$search = $_GET['search'];
if (!$button)
echo "you didn't submit a keyword";
else {
if (strlen($search) <= 1)
echo "Search term too short";
else {
echo "You searched for <b>$search</b> <hr size='1'></br>";
mysql_connect("", "", "");
mysql_select_db("");
$search_exploded = explode(" ", $search);
foreach ($search_exploded as $search_each) {
$x++;
if ($x == 1)
$construct .= "keywords LIKE '%$search_each%'";
else
$construct .= "AND keywords LIKE '%$search_each%'";
}
$construct = "SELECT * FROM SEARCH_ENGINE WHERE $construct";
$run = mysql_query($construct);
$foundnum = mysql_num_rows($run);
if ($foundnum == 0)
echo "Sorry, there are no matching result for <b>$search</b>.</br></br>1.
Try more general words. for example: If you want to search 'how to create a website'
then use general keyword like 'create' 'website'</br>2. Try different words with similar
meaning</br>3. Please check your spelling";
else {
echo "$foundnum results found !<p>";
while ($runrows = mysql_fetch_assoc($run)) {
$title = $runrows['title'];
$desc = $runrows['description'];
$url = $runrows['url'];
echo "
<a href='$url'><b>$title</b></a><br>
$desc<br>
<a href='$url'>$url</a><p>
";
}
}
}
}
?>
答案 0 :(得分:3)
答案 1 :(得分:1)
检查PHP版本,尝试使用mysqli_connect()
警告强> 此扩展在PHP 5.5.0中已弃用,并且已在PHP 7.0.0中删除。相反,应该使用MySQLi或PDO_MySQL扩展。另请参阅MySQL:选择API指南和相关的常见问题解答以获取更多信息。该功能的替代方案包括: mysqli_connect() PDO :: __构建体()