- PDO Params are now properly (mostly..) binded, bool, null and int are now handled correctly
This commit is contained in:
parent
c1755d250b
commit
9a9f473f3f
|
@ -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();
|
||||
|
|
Loading…
Reference in New Issue