Created
October 22, 2014 18:03
-
-
Save seagoj/86c919f6d4c821557eaa to your computer and use it in GitHub Desktop.
Discern between SELECT, INSERT & UPDATE
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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