PHP 未使用 MYSQL 数据库进行更新



下面的代码显示了我访问MYSQL数据库的连接,但由于某种原因,一旦它从数据库中获取了详细信息,就不会更新PHP页面。例如,当前表lastWinner是一个包含"David"的字符串数据类型。保存php文件后,输出显示为David,但如果我更改mysql数据库中的值,则输出不会更改。

  <div id="navigation">
     <?php
       $host     = "localhost";
       $username = "DB_USER";
       $password = "PASSWORD";
       $db_name  = "DB_NAME";
       $message = "The last person to win the lottery is: ";
       mysql_connect("$host", "$username", "$password") or die (mysql_error ());
       mysql_select_db("$db_name") or die(mysql_error());               
       $total = "SELECT lastWinner AS total FROM info";
       $rs = mysql_query($total);                                                                                              
       while($row = mysql_fetch_array($rs)) {
             echo $message.$row['total'];
       }                                                        
       mysql_close();
    ?>
  </div>

这是将数据发送到数据库本身的代码。

  public static boolean updateInfo() {
    try {
        if (Settings.DisableMYSQL == true)
            return false;
        Statement stmt = connection.createStatement();
        if (Lottery.getCurrentLotteryWinner() == null
                && Lottery.getLastLotteryWinner() == null)
            stmt.executeUpdate("UPDATE info SET lastWinner = 'There current isn't a lottery winner!'");
        else if (Lottery.getCurrentLotteryWinner() != null
                && Lottery.getLastLotteryWinner() == null)
            stmt.executeUpdate("UPDATE info SET lastWinner = '"
                    + Lottery.getCurrentLotteryWinner() + "'");
        else
            stmt.executeUpdate("UPDATE info SET lastWinner = '"
                    + Lottery.getLastLotteryWinner() + "'");
            stmt.executeUpdate("UPDATE info SET moneyEarned = '"
                + Lottery.options.size() + "'");
    } catch (Throwable e) {
        if (System.currentTimeMillis() - lastConnection > 10000) {
            destroyConnection();
            createConnection();
            lastConnection = System.currentTimeMillis();
        }
    }
    return false;
}   

我的网络主机遇到了困难,做了一些事情使它工作起来。

最新更新