migrate-sqlite-to-pg: DSN-Parsen für pdo_pgsql
This commit is contained in:
@@ -13,7 +13,14 @@ if (!$pgUrl) {
|
||||
$sqlite = new PDO('sqlite:' . $sqlitePath);
|
||||
$sqlite->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
$pg = new PDO(preg_replace('#^postgresql://#', 'pgsql://', $pgUrl));
|
||||
// PDO pgsql akzeptiert keine // URLs -> DSN-Form
|
||||
preg_match('#^[a-z+]+://([^:@/]*)(?::([^@/]*))?@([^:/?]*)(?::(\d+))?/([^?]*)(?:\?(.*))?$#', $pgUrl, $m);
|
||||
[$authUser, $authPass, $host, $port, $dbname] = [$m[1] ?? 'essens', $m[2] ?? '', $m[3] ?? 'localhost', $m[4] ?? '5432', $m[5] ?? 'essens'];
|
||||
$pg = new PDO(
|
||||
sprintf('pgsql:host=%s;port=%s;dbname=%s;user=%s;password=%s', $host, $port, $dbname, $authUser, $authPass),
|
||||
$authUser,
|
||||
$authPass,
|
||||
);
|
||||
$pg->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
|
||||
$copy = $pg->beginTransaction();
|
||||
|
||||
Reference in New Issue
Block a user