- PDO Params are now properly (mostly..) binded, bool, null and int are now handled correctly

This commit is contained in:
Dave Mc Nicoll 2023-11-17 16:00:29 -05:00
parent c1755d250b
commit 9a9f473f3f
1 changed files with 23 additions and 3 deletions

View File

@ -29,7 +29,7 @@ class PdoObject extends PDO {
return $statement;
}
}
catch (\PDOException $e) {
catch (\Throwable $e) {
throw new \PdoException($e->getMessage() . " `$sql` with data:" . json_encode($parameters));
}
}
@ -50,7 +50,7 @@ class PdoObject extends PDO {
return $this->execute($statement, $parameters, true);
}
}
catch (\PDOException $e) {
catch (\Throwable $e) {
throw new \PdoException($e->getMessage() . " `$sql` with data:" . json_encode($parameters));
}
@ -82,7 +82,27 @@ class PdoObject extends PDO {
$this->beginTransaction();
}
$this->executionStatus = empty($parameters) ? $statement->execute() : $statement->execute($parameters);
foreach($parameters as $key => $value) {
switch(strtolower(gettype($value))) {
case "boolean":
$statement->bindValue($key, $value, Pdo::PARAM_BOOL);
break;
case "integer":
$statement->bindValue($key, $value, Pdo::PARAM_INT);
break;
case "null":
$statement->bindValue($key, $value, Pdo::PARAM_NULL);
break;
case "string":
default:
$statement->bindValue($key, (string) $value, Pdo::PARAM_STR);
}
}
$this->executionStatus = $statement->execute();
if ( $this->executionStatus ) {
$this->lastInsertId = $this->lastInsertId();