datetime,SELECT和准备好的语句

时间:2013-02-09 23:05:10

标签: php mysqli prepared-statement

我希望同一个查询在准备好的语句中运行两次,但是无法使其工作?

这是我得到的:

$yearFrom = date("Y-01-01");
$yearTo = date("Y-12-31");

$monthFrom = date("Y-01-01");
$monthTo = date("Y-01-31");

$stmt = $mysqli->stmt_init();

$getuserpoints = "SELECT SUM(points) as userpoints FROM ".$prefix."_publicpoints
                    WHERE date BETWEEN ? AND ? AND fk_player_id = ?";

if($stmt->prepare($getuserpoints)){
    $stmt->bind_param('ssi', $yearFrom,$yearTo,$playerid);
    $stmt->execute();
    if (!$stmt->execute()) {
        echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
    }
    $stmt->bind_result($userPoints);

    $stmt->bind_param('ssi', $monthFrom,$monthTo,$playerid);
    $stmt->execute();
    if (!$stmt->execute()) {
        echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
    }
    $stmt->bind_result($userMPoints);
} 

我认为是造成麻烦的日期时间。我该怎么做?

提前致谢: - )

0 个答案:

没有答案