下面的代码显示了我到达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;
}
答案 0 :(得分:0)
我的虚拟主机遇到了困难,做了一些让它工作的东西。