diff --git a/library/Icinga/Application/Hook/DbMigrationHook.php b/library/Icinga/Application/Hook/DbMigrationHook.php index eb05cd8ad..5b35f3ccf 100644 --- a/library/Icinga/Application/Hook/DbMigrationHook.php +++ b/library/Icinga/Application/Hook/DbMigrationHook.php @@ -64,13 +64,13 @@ abstract class DbMigrationHook implements Countable */ public static function tableExists(Connection $conn, string $table): bool { - /** @var stdClass $query */ - $query = $conn->prepexec( + /** @var false|int $exists */ + $exists = $conn->prepexec( 'SELECT EXISTS(SELECT 1 FROM information_schema.tables WHERE table_name = ?) AS result', $table - )->fetch(PDO::FETCH_OBJ); + )->fetchColumn(); - return $query->result; + return (bool) $exists; } /** @@ -122,18 +122,13 @@ abstract class DbMigrationHook implements Countable return null; } - $pdoStmt = $conn->prepexec( + /** @var false|string $collation */ + $collation = $conn->prepexec( 'SELECT collation_name FROM information_schema.columns WHERE table_name = ? AND column_name = ?', [$table, $column] - ); + )->fetchColumn(); - /** @var false|stdClass $result */ - $result = $pdoStmt->fetch(PDO::FETCH_OBJ); - if ($result === false) { - return null; - } - - return $result->collation_name; + return ! $collation ? null : $collation; } /**