Use PDO::fetchColumn() where applicable

This commit is contained in:
Yonas Habteab 2023-09-15 14:04:59 +02:00 committed by Johannes Meyer
parent d2ce60d4c0
commit 47b214ee1b

View File

@ -64,13 +64,13 @@ abstract class DbMigrationHook implements Countable
*/ */
public static function tableExists(Connection $conn, string $table): bool public static function tableExists(Connection $conn, string $table): bool
{ {
/** @var stdClass $query */ /** @var false|int $exists */
$query = $conn->prepexec( $exists = $conn->prepexec(
'SELECT EXISTS(SELECT 1 FROM information_schema.tables WHERE table_name = ?) AS result', 'SELECT EXISTS(SELECT 1 FROM information_schema.tables WHERE table_name = ?) AS result',
$table $table
)->fetch(PDO::FETCH_OBJ); )->fetchColumn();
return $query->result; return (bool) $exists;
} }
/** /**
@ -122,18 +122,13 @@ abstract class DbMigrationHook implements Countable
return null; 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 = ?', 'SELECT collation_name FROM information_schema.columns WHERE table_name = ? AND column_name = ?',
[$table, $column] [$table, $column]
); )->fetchColumn();
/** @var false|stdClass $result */ return ! $collation ? null : $collation;
$result = $pdoStmt->fetch(PDO::FETCH_OBJ);
if ($result === false) {
return null;
}
return $result->collation_name;
} }
/** /**