Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit dbdfc1c

Browse files
author
Ady
committed
Merge branch 'fix' into 'master'
fix: handle null value in insert statement See merge request adynemo/maintenance-bundle!4
2 parents 387e48d + 08626fe commit dbdfc1c

3 files changed

Lines changed: 9 additions & 15 deletions

File tree

Drivers/Query/DefaultQuery.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,11 @@ public function insertQuery($ttl, $db)
8282
return $this->exec(
8383
$db,
8484
sprintf(
85-
'INSERT INTO %s (ttl) VALUES (?)',
86-
$this->options['table']
85+
'INSERT INTO %1$s (ttl) VALUES (%2$s)',
86+
$this->options['table'],
87+
$ttl ? '?' : 'NULL'
8788
),
88-
[1 => $ttl]
89+
$ttl ? [1 => $ttl] : []
8990
);
9091
}
9192
}

Drivers/Query/DsnQuery.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,11 @@ public function insertQuery($ttl, $db)
6363
return $this->exec(
6464
$db,
6565
sprintf(
66-
'INSERT INTO %s (ttl) VALUES (?)',
67-
$this->options['table']
66+
'INSERT INTO %1$s (ttl) VALUES (%2$s)',
67+
$this->options['table'],
68+
$ttl ? '?' : 'NULL'
6869
),
69-
[1 => $ttl]
70+
$ttl ? [1 => $ttl] : []
7071
);
7172
}
7273
}

Drivers/Query/PdoQuery.php

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -158,15 +158,7 @@ protected function fetch($db, $query, array $args = [])
158158
private function bindValues($stmt, array $args)
159159
{
160160
foreach ($args as $arg => $val) {
161-
if (is_null($val)) {
162-
$type = \PDO::PARAM_NULL;
163-
} elseif (is_int($val)) {
164-
$type = \PDO::PARAM_INT;
165-
} else {
166-
$type = \PDO::PARAM_STR;
167-
}
168-
169-
$stmt->bindValue($arg, $val, $type);
161+
$stmt->bindValue($arg, $val, is_int($val) ? \PDO::PARAM_INT : \PDO::PARAM_STR);
170162
}
171163
}
172164
}

0 commit comments

Comments
 (0)