1

我是 mysql 和 php 的菜鸟,只想问我这样做是否正确:

  1. 我想从“lastTurn”超过 12 小时的表中选择。这是正确的方法吗。我最关心 12 小时的时间戳

    $queryQuit = mysql_query("SELECT match_id, lastTurn FROM active_matches WHERE matchStatus=0 AND noticeSent < 2 AND lastTurn < NOW() - INTERVAL 12 HOUR");

  2. 我使用 Asihttprequest 向服务器发送数据。如果我发送一个 int,是否需要在它进入数据库之前对其进行转换?

    //score is an int
    $score = mysql_real_escape_string($_POST['score']); 
    
    //Update a table where the field is an int 
     "UPDATE hiscore SET score=score + '$score' WHERE username='$username'"
    

提前致谢

4

1 回答 1

1
  1. 这看起来是正确的

  2. 如果要确保保存整数,则需要强制转换为 int

代码示例:

$score = mysql_real_escape_string((int) $_POST['score']);

或者

$score = mysql_real_escape_string(intval($_POST['score']));
于 2012-04-28T21:46:56.400 回答