如果php脚本突然无效,该怎么办

时间:2011-02-13 00:27:33

标签: php mysql

我有这个登录代码,它在我睡觉前的昨晚工作。没有人用过我的电脑。但今天早上突然停止了工作。我的其他代码也无法正常工作。事实上,我确保在离开之前他们都在工作。 我重新格式化了我的硬盘。我有一个工作项目的备份。我无法理解为什么它不起作用。以前有人经历过这个吗?

<?php 




include('conn.php');








        $uname = mysql_real_escape_string($_POST['yname']);
        $pword = $_POST['pword'];
        $pwordmd5=md5($pword);



        $result = query_database("SELECT * FROM admin_table WHERE   Uneym = '$uname' AND Pwerd = '$pwordmd5'", "onstor", $link);
        $num_rows = mysql_num_rows($result);



        if ($result) {
            if ($num_rows > 0) {
                session_start();
                $_SESSION['loginAdmin'] = "1";



                //added feb 5 2011

                $_SESSION['Uneym'] = $uname;






                query_database("UPDATE admin_table SET Current='1' WHERE   Uneym = '$uname' AND Pwerd = '$pwordmd5'", "onstor", $link);



                    header ("Location: adminpage.php");


            }



            else {
                session_start();
                $_SESSION['loginAdmin'] = "";
                header ("Location: ../login.php");
            }   
        }
        else {
            $errorMessage = "Error logging on, please try again.";
        }











?>

我在php错误日志中有这个:

[12-Feb-2011 23:49:14] PHP Warning:  mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: [2002] A connection attempt failed because the connected party did not  (trying to connect via tcp://localhost:3306) in X:\wamp\www\pos\php\conn.php on line 6

[12-Feb-2011 23:49:14] PHP Warning:  mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

 in X:\wamp\www\pos\php\conn.php on line 6

[12-Feb-2011 23:49:14] PHP Fatal error:  Maximum execution time of 60 seconds exceeded in X:\wamp\www\pos\php\conn.php on line 6

    [12-Feb-2011 23:49:35] PHP Warning:  mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: [2002] A connection attempt failed because the connected party did not  (trying to connect via tcp://localhost:3306) in X:\wamp\www\pos\php\conn.php on line 6

    [12-Feb-2011 23:49:35] PHP Warning:  mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

     in X:\wamp\www\pos\php\conn.php on line 6

    [12-Feb-2011 23:49:35] PHP Fatal error:  Maximum execution time of 60 seconds exceeded in X:\wamp\www\pos\php\conn.php on line 6

    [12-Feb-2011 23:50:01] PHP Warning:  mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: [2002] A connection attempt failed because the connected party did not  (trying to connect via tcp://localhost:3306) in X:\wamp\www\pos\php\conn.php on line 6

    [12-Feb-2011 23:50:01] PHP Warning:  mysql_connect() [<a href='function.mysql-connect'>function.mysql-connect</a>]: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

     in X:\wamp\www\pos\php\conn.php on line 6

这是错误日志指出的conn.php:

<?php



function open_connection($host, $user, $password){
    return mysql_connect($host, $user, $password);

}

function close_connection($link){
    return mysql_close($link);

}

function query_database($query, $database, $link){
    mysql_select_db($database, $link);
    return mysql_query($query, $link);
}

function fetcher($result){
    return mysql_fetch_assoc($result);

}

function query_checker($query){
    if(!$query){
    echo "error!".mysql_error();
}
    return mysql_error();

}

$link=open_connection('localhost','root', '1234');
?>

还没有修改conn.php,因为它是你想连接数据库时应该写的第一个脚本。还有一件事,在我重新格式化之前,整个项目都是一个驱动器。现在我在x驱动器上。我不确定这是不是问题。

3 个答案:

答案 0 :(得分:4)

您的数据库似乎已关闭。尝试重新启动你的mysql服务。

答案 1 :(得分:1)

基于您所获得的错误,问题不在您的代码中,而是在您的mysql服务器中。检查服务器设置,它是否仍在运行,它是否已损坏,等等。

答案 2 :(得分:1)

如果无法启动服务器,则某些其他应用程序可能与服务器冲突。例如Skype使用相同的端口,如果Skype也打开,则wamp可能无法启动。