Skip to content

Instantly share code, notes, and snippets.

@seagoj
Created October 22, 2014 18:03
Show Gist options
  • Save seagoj/86c919f6d4c821557eaa to your computer and use it in GitHub Desktop.
Save seagoj/86c919f6d4c821557eaa to your computer and use it in GitHub Desktop.
Discern between SELECT, INSERT & UPDATE
$stmt = $this->connection->prepare($queryString);
$executeResult = !is_null($params)
? $stmt->execute($params)
: $stmt->execute();
$data = $stmt->fetchAll($fetchType);
$isInsertStatement = empty($data)
&& $executeResult
&& ($lastInsertId = $this->connection->lastInsertId()) !== 0;
$isUpdateStatement = empty($data);
if ($isInsertStatement) {
$data = array('insert_id' => $lastInsertId);
} else if ($isUpdateStatement) {
$data = $executeResult;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment