一千萬個為什麽

搜索

為什麽我的php腳本會凍結?

是什麽導致我的PHP代碼凍結?我知道這是while循環的原因,但我有$ max_threads--;最後所以它不應該這樣做。

<html>
    <head>
        <?php
            $db = mysql_connect("host","name","pass") or die("Can't connect to host");
            mysql_select_db("dbname",$db) or die("Can't connect to DB"); 

            $sql_result = mysql_query("SELECT MAX(Thread) FROM test_posts", $db);

            $rs = mysql_fetch_row($sql_result);

            $max_threads = $rs[0];

            $board = $_GET['board'];
        ?>



    </head>

    <body>


        <?php


            While($max_threads >= 0)
            {
                $sql_result = mysql_query("SELECT MIN(ID) FROM test_posts WHERE Thread=".$max_threads."", $db);
                $rs = mysql_fetch_row($sql_result);

                $sql_result = mysql_query("SELECT post FROM test_posts WHERE ID=".$rs[0]."", $db);
                $post = mysql_fetch_row($sql_result);

                $sql_result = mysql_query("SELECT name FROM test_posts WHERE ID=".$rs[0]."", $db);
                $name = mysql_fetch_row($sql_result);

                $sql_result = mysql_query("SELECT trip FROM test_posts WHERE ID=".$rs[0]."", $db);
                $trip = mysql_fetch_row($sql_result);

                if(!empty($post))
                    echo'<div class="postbox">

'.$name[0].'['.$trip[0].']


' . $post[0] . '

[Reply]</div>';

                $max_threads--;
            }

        ?>
    </body>
</html>

最佳答案

首先,我建議完全擺脫無關的HTML位。然後,逐行緩慢地構建代碼,看看是否可以找到有問題的行。因此,編寫一個只連接到數據庫的腳本,看看會發生什麽。

如果您發現此代碼...

<?php
    $db = mysql_connect("host","name","pass") or die("Can't connect to host");
    mysql_select_db("dbname",$db) or die("Can't connect to DB"); 
?>

...導致凍結,然後它很容易成為MySQL服務器的問題。

但是,如果瀏覽器本身崩潰,這聽起來像是系統的問題而不是PHP或MySQL正在做的事情......

轉載註明原文: 為什麽我的php腳本會凍結?