I have a database from which I'd like to return a tuple of two elements (ID and URL) with check digit to see if operation was successful.
Is correct this code to return this tuple and control?
public function getManufacturer($id) {
$stmtManufacturer = $this->dbConnection->prepare("SELECT ID, URL FROM ERP.MANUFACTURER WHERE ID = ?");
$stmtManufacturer->bind_param("i", $id);
$stmtManufacturer->execute();
$stmtManufacturer->store_result();
$stmtManufacturer->bind_result($id, $url);
$stmtManufacturer->fetch();
$stmtManufacturer->close();
return [
ACTION_RESULT => $this->processServerResponse($stmtManufacturer),
"data" =>
[
"id" => $id,
"url" => $url
]
];
}
ACTION_RESULT
is defined as a constant in the class.
I think function processServerResponse()
could be improved:
public function processServerResponse($stmt) {
if ($stmt->errno || $stmt->affected_rows === 0) {
$_actionResult = 0;
} else if ($stmt->affected_rows !== 0) {
$_actionResult = 1;
}
return $_actionResult;
}