Skip to content

Commit c8feb7c

Browse files
authored
Merge pull request #8 from kaushikindianic/fix-getBy-find-null-result
fix: return null if no result found
2 parents 10ce3a8 + 5380520 commit c8feb7c

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

src/AbstractPdoObjectType.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,14 @@ public function __construct(PDO $pdo, $config)
2121
// TODO: rename to getOneBy
2222
public function getBy($key, $value)
2323
{
24-
$stmt = $this->pdo->prepare('SELECT * FROM ' . $this->tableName . ' WHERE ' . $key . ' = :value');
25-
$result = $stmt->execute(['value'=>$value]);
26-
return $this->processRow($stmt->fetch(PDO::FETCH_ASSOC));
24+
$stmt = $this->pdo->prepare('SELECT * FROM '.$this->tableName.' WHERE '.$key.' = :value');
25+
$stmt->execute(['value' => $value]);
26+
27+
if ($result = $this->processRow($stmt->fetch(PDO::FETCH_ASSOC))) {
28+
return $result;
29+
}
30+
31+
return null;
2732
}
2833

2934
public function getAllBy($key, $value)

0 commit comments

Comments
 (0)