我的搜索查询出现问题,在多次搜索网站后,网站崩溃,我不确定是否是由于我在GoDaddy支付的内存不足或者我的搜索查询是抛出错误或要求太多资源。
请问您可以在此处测试搜索:http://cameras.specced.co.uk
请输入几种不同的相机型号并多次执行此操作,搜索查询将停止工作,网站将不再有效。
以下是搜索查询:
$model_search_query = $cameras_pdo->prepare("SELECT * FROM models WHERE concat_ws(' ',brand_name,model) LIKE :search LIMIT 5");
$model_search_query->execute(array(':search' => "%" . $_POST['search'] . "%"));
while ($model_search = $model_search_query->fetch(PDO::FETCH_ASSOC)) {
$brand_search_query = "SELECT brand FROM brands WHERE id =" . $model_search['brand'];
$brand_search = mysqli_fetch_assoc(mysqli_query($cameras, $brand_search_query)); ?>
<a href="compare.php?compare_1=<?php echo $model_search['id'];?>">
<div class="search_result">
<div class="search_result_image">
<!-- IMAGE REMOVED TO TEST IF THIS WAS CAUSING THE ISSUE -->
</div>
<div class="search_result_text">
<?php echo $brand_search['brand'] . " " . $model_search['model']; ?>
</div>
</div>
</a>
<?php } ?>
我已经从搜索结果中删除了图片,只是因为它太大而且在下拉搜索中同时加载了太多导致问题,但是网站在搜索了几次后仍然崩溃。
这是我在Safari中收到的错误,
Safari无法打开....因为服务器意外断开连接...
感谢您的任何帮助
编辑:
以下是我的fetch.php的全部内容,当用户搜索http://cameras.specced.co.uk标题中右上角的搜索栏时,AJAX会包含该内容。
<?php ini_set('display_errors', 'On'); ?>
<!-- REQUIRE DB -->
<?php
$servername = "xxx";
$username = "xxx";
$password = "xxx";
$dbname = "xxx";
?>
<?php
$cameras = mysqli_connect($servername, $username, $password, $dbname);
$cameras_pdo = new PDO('mysql:host=xxx;dbname=xxx', 'xxx', 'xxx');
?>
<?php
$model_search_query = $cameras_pdo->prepare("SELECT * FROM models WHERE concat_ws(' ',brand_name,model) LIKE :search LIMIT 5");
$model_search_query->execute(array(':search' => "%" . $_POST['search'] . "%"));
while ($model_search = $model_search_query->fetch(PDO::FETCH_ASSOC)) {
$brand_search_query = "SELECT brand FROM brands WHERE id =" . $model_search['brand'];
$brand_search = mysqli_fetch_assoc(mysqli_query($cameras, $brand_search_query));
p?1=' . $_POST['current'] . "&2=" . $model_search['id'] . '">';
echo '<a href="compare.php?compare_1=' . $model_search['id'] . '">'.
'<div class="search_result">' .
'<div class="search_result_image">' .
'<img src="http://www.specced.co.uk/images/cameras/[' . $model_search['id'] . ']_front.png">' .
'</div>' .
'<div class="search_result_text">' .
$brand_search['brand'] . " " . $model_search['model'] .
'</div>' .
'</div>' .
'</a>';
}
?>
答案 0 :(得分:0)
当网站停止响应时,如果您在浏览器“网络”面板中检查开发者控制台并检查来自fetch.php的响应,您将看到最后一个HTTP 200响应仅包含以下内容:
<!-- REQUIRE DB -->
后续请求为空白。因此,我猜测PHP在尝试建立数据库连接时会死掉。检查您的error_log并在此处发布您的错误作为评论!完成后关闭数据库连接吗?