From 514c128957a670efa1ca9584df4f64083342df51 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Thu, 14 Jul 2011 06:30:07 -0700 Subject: [PATCH] Fixed bug in bindings that was causing null to be saved as 0 in MySQL. --- system/db.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/system/db.php b/system/db.php index 4769fc74..c4460513 100644 --- a/system/db.php +++ b/system/db.php @@ -52,7 +52,21 @@ public static function query($sql, $bindings = array(), $connection = null) { $query = static::connection($connection)->prepare($sql); - $result = $query->execute($bindings); + $bindings = array_values($bindings); + + foreach ($bindings as $key => &$binding) + { + if (is_null($binding)) + { + $query->bindValue($key + 1, null, \PDO::PARAM_INT); + } + else + { + $query->bindParam($key + 1, $binding); + } + } + + $result = $query->execute(); if (strpos(strtoupper($sql), 'SELECT') === 0) {