【发布时间】:2014-07-16 10:09:32
【问题描述】:
我想知道如何解决 WampServer 的“apache http 服务器停止工作并已关闭”错误消息的问题。我使用 Vista 作为操作系统,并且安装了具有以下特性的 WampServer 2.1:
Apache 版本:2.2.17 PHP版本:5.3.5 MySQL 版本:5.5.8
我在互联网上搜索过这个错误,我发现原因是 mysql_close() 语法,你可以在这个链接上注意到:http://forum.wampserver.com/read.php?2,52654,52832 .但奇怪的是,我没有像您在下面的代码中注意到的那样的语法错误:
<?php
$a = $_REQUEST['subject1'];
$con=mysqli_connect("localhost","root","","wkayetdb");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT id, message FROM notifications WHERE subject = '".$a."' AND status = 'unseen' ORDER BY id DESC LIMIT 0, 1");
$notification = array();
while($row = mysqli_fetch_array($result)) {
$id = $row['id'];
$message = $row['message'];
if($message=="a ajouté"){
$result1 = mysqli_query($con,"SELECT notifications.id AS id, groupe.id_groupe AS groupid, eventsgroupe.start AS startdate, groupe.groupename AS groupname, notifications.message AS message, eventsgroupe.title AS title, notifications.status as status FROM notifications, eventsgroupe, groupe WHERE notifications.actor = groupe.id_groupe AND notifications.object = eventsgroupe.id AND notifications.id = '".$id."'");
while($row1 = mysqli_fetch_array($result1)) {
$notification = array('id'=>$row1['id'],'groupid'=>$row1['groupid'],'startdate'=>$row1['startdate'],'groupname'=>$row1['groupname'],'message'=>$row1['message'],'title'=>$row1['title'],'status'=>$row1['status']);
}
}
elseif(($message=="a accepté votre invitation de rejoindre votre groupe")||($message=="a décliné votre invitation de rejoindre votre groupe")){
$result2 = mysqli_query($con,"SELECT notifications.id AS id, groupe.groupename AS groupname, notifications.message AS message, user.name AS username FROM notifications, user, groupe WHERE notifications.actor = user.id_user AND notifications.object = groupe.id_groupe AND notifications.id = '".$id."'");
while($row2 = mysqli_fetch_array($result2)) {
$notification = array('id'=>$row2['id'],'username'=>$row2['username'],'message'=>$row2['message'],'groupname'=>$row2['groupname']);
}
}
}
echo json_encode($notification);
mysqli_close($con);
?>
只关注这两行:$con=mysqli_connect("localhost","root","","wkayetdb"); 和 mysqli_close($con);。
我真的很想知道问题到底是什么,那么有人知道解决方案吗?
【问题讨论】:
-
你确定是这个脚本引起的吗?如果你是什么让你这么认为?如果您确定,请尝试删除代码行,直到您确定导致问题的行。
-
@RiggsFolly:我没有说上面的脚本是问题的原因,我说的是一般情况。此外,我认为删除代码行直到我确定导致问题的行不会是一个有用的解决方案,因为其他行没有任何影响。
-
只是一个建议:您是否尝试过在关闭连接之前释放语句句柄?
mysql_free_result($result);用于所有 3 条语句。或者只是将mysql_close()完全排除在外,因为这是在脚本完成时由 PHP 自动完成的。 -
@RiggsFolly:嗯,我还没有真正尝试过这些方法中的每一种。但奇怪的是,当我在另一台计算机上运行上面的代码时,我没有遇到这样的问题。所以很明显问题的原因是我的电脑上安装了 WampServer。顺便说一句,我正在虚拟机上运行我的应用程序。
标签: mysql apache message wampserver