Skip to content

Commit

Permalink
Fix for parameter types.
Browse files Browse the repository at this point in the history
  • Loading branch information
charsleysa committed May 29, 2014
1 parent 4745ee7 commit 6a9b77c
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion idiorm.php
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,20 @@ protected static function _execute($query, $parameters = array(), $connection_na
$statement = self::get_db($connection_name)->prepare($query);
self::$_last_statement = $statement;
$time = microtime(true);
$q = $statement->execute($parameters);

$count = count($parameters);
for ($i = 0; $i < $count; $i++) {
$type = PDO::PARAM_STR;
if (is_null($parameters[i])) $type = PDO::PARAM_NULL;
if (is_bool($parameters[i])) $type = PDO::PARAM_BOOL;
if (is_numeric($parameters[i])) {
$type = PDO::PARAM_INT;
$parameters[$i] = +($parameters[$i]);
}
$statement->bindParams($i + 1, $parameters[$i], $type);
}

$q = $statement->execute();
self::_log_query($query, $parameters, $connection_name, (microtime(true)-$time));

return $q;
Expand Down

2 comments on commit 6a9b77c

@mgalang
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to break queries when using named placeholders with raw_query()?

@treffynnon
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, that is gonna be the case - I hadn't noticed before. The problem here is the the for loop is trouncing the named param with a ordered/positional/integer one.

@mgalang Please could you create ticket for this on the Idiorm project referring to: https://github.com/j4mie/idiorm/blob/master/idiorm.php#L415

@charsleysa if you get a chance please could you take a look at this and prepare a pull request?

Please # to comment.