本文整理汇总了PHP中SimpleXMLElement::createElement方法的典型用法代码示例。如果您正苦于以下问题:PHP SimpleXMLElement::createElement方法的具体用法?PHP SimpleXMLElement::createElement怎么用?PHP SimpleXMLElement::createElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleXMLElement
的用法示例。
在下文中一共展示了SimpleXMLElement::createElement方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: submitAction
function submitAction($playerID, $gameID, $xml)
{
global $sqlhost, $sqlusername, $sqlpassword;
$result = new SimpleXMLElement("<action/>");
if ($playerID > -1) {
if ($xml->xCoord == null or $xml->yCoord == null or $xml->actionType == null) {
$error = $result->createElement('actionError', "Incomplete data in submission. Please try again.");
$error = $resultBase->appendChild($error);
} else {
$conn = new mysqli($sqlhost, $sqlusername, $sqlpassword);
if ($conn->connect_error) {
error_log("submitAction.php - Connection failed: " . $conn->connect_error);
$error = $result->addChild('actionError', "Internal error occurred, please try again later.");
}
#Delete any previous actions from this player
if ($deleteStmt = $conn->prepare("DELETE FROM sweepelite.actionqueue WHERE playerID=? AND gameID=?")) {
$deleteStmt->bind_param("ii", $xml->playerID, $gameID);
$deleteStmt->execute();
$deleteStmt->close();
} else {
error_log("submitAction.php - Unable to prepare delete statement, forging ahead anyways. " . $conn->errno . ": " . $conn->error);
}
#Check if player can actually submit actions or not
if ($openGameStmt = $conn->prepare("SELECT status FROM sweepelite.games WHERE gameID=?")) {
$openGameStmt->bind_param("i", $gameID);
$openGameStmt->execute();
$openGameStmt->bind_result($gameStatus);
$openGameStmt->fetch();
$openGameStmt->close();
if ($gameStatus === "OPEN") {
if ($aliveStmt = $conn->prepare("SELECT COUNT(*) FROM sweepelite.playerstatus WHERE gameID=? AND playerID=? AND status!=0")) {
$aliveStmt->bind_param("ii", $gameID, $playerID);
$aliveStmt->execute();
$aliveStmt->bind_result($count);
$aliveStmt->fetch();
$aliveStmt->close();
if ($count > 0) {
#Add the current action they have queued up instead.
if ($insertStmt = $conn->prepare("INSERT INTO sweepelite.actionqueue (playerID, gameID, xCoord, yCoord, actionType) VALUES (?, ?, ?, ?, ?)")) {
$insertStmt->bind_param("iiiii", $playerID, $gameID, $xml->xCoord, $xml->yCoord, $xml->actionType);
$updated = $insertStmt->execute();
if (!$updated) {
error_log("submitAction.php - Error occurred inserting player action into queue. " . $insertStmt->errno . ": " . $insertStmt->error);
$error = $result->addChild('error', "Internal error occurred, please try again later.");
$insertStmt->close();
} else {
$insertStmt->close();
$error = $result->addChild('action', "Action submitted!");
#Update current player status to set current player's action awaiting status to false
if ($updateStmt = $conn->prepare("UPDATE sweepelite.playerstatus SET awaitingAction=0 WHERE playerID=? AND gameID=?")) {
$updateStmt->bind_param("ii", $playerID, $gameID);
$updateStmt->execute();
$updateStmt->close();
} else {
error_log("submitAction.php - Error occurred updating the fact that a player has submitted an action.");
}
}
} else {
error_log("submitAction.php - Unable to prepare insert statement, need to fail. " . $conn->errno . ": " . $conn->error);
$error = $result->addChild('actionError', "Internal error occurred, please try again later.");
}
} else {
error_log("submitAction.php - Player not allowed to submit actions.");
#Find out why player is not allowed to submit actions.
if ($deadStmt = $conn->prepare("SELECT COUNT(*) FROM sweepelite.playerstatus WHERE gameID=? AND playerID=? AND status=0")) {
$deadStmt->bind_param("ii", $xml->playerID, $gameID);
$deadStmt->execute();
$deadStmt->bind_result($count);
$deadStmt->fetch();
$deadStmt->close();
if ($count > 0) {
$error = $result->addChild('actionError', "You are dead.");
} else {
$error = $result->addChild('actionError', "You are not a participant in this game.");
}
} else {
error_log("submitAction.php - Unable to prepare dead check statement. " . $conn->errno . ": " . $conn->error);
$error = $result->addChild('actionError', "You are not allowed to participate in this game at this time.");
}
}
}
} else {
$error = $result->addChild('actionError', "This game is over. Please wait for the next game to be deployed.");
}
}
}
} else {
$error = $result->addChild('actionError', "You must be logged in to submit actions.");
}
return str_replace('<?xml version="1.0"?>', "", $result->asXML());
}