[web-master] main: Rename our old connect helper method, so that it doesn't clash with the PDO::connect method

From: Date: Thu, 21 May 2026 13:27:10 +0000
Subject: [web-master] main: Rename our old connect helper method, so that it doesn't clash with the PDO::connect method
Groups: php.webmaster 
Request: Send a blank email to php-webmaster+get-33718@lists.php.net to get a copy of this message
Author: Derick Rethans (derickr) Date: 2026-05-21T14:26:44+01:00 Commit: https://github.com/php/web-master/commit/3618b6955a941a9945b124e2eb1f970f8dc0dc71 Raw diff: https://github.com/php/web-master/commit/3618b6955a941a9945b124e2eb1f970f8dc0dc71.diff Rename our old connect helper method, so that it doesn't clash with the PDO::connect method Changed paths: M include/login.inc M public/entry/event.php M public/entry/svn-account.php M public/entry/user-note.php M public/entry/user-notes-vote.php M public/fetch/allusers.php M public/fetch/cvsauth.php M public/fetch/cvsforwarding.php M public/fetch/email-aliases.php M public/fetch/events.php M public/fetch/user-notes-rss.php M public/fetch/user-notes.php M public/fetch/user-profile.php M public/fetch/user.php M public/forgot.php M public/github-webhook.php M public/manage/event.php M public/manage/user-notes.php M public/manage/users.php M scripts/email-note-summaries M scripts/remove-low-rated-notes M src/DB.php Diff: diff --git a/include/login.inc b/include/login.inc index e7ac61a..b4a7aa3 100644 --- a/include/login.inc +++ b/include/login.inc @@ -28,7 +28,7 @@ if (isset($_POST["user"], $_POST["pw"])) { } // Login form, if the user is not yet logged in -if (!$cuser || !$cpw || !verify_password(DB::connect(), $cuser,$cpw)) { +if (!$cuser || !$cpw || !verify_password(DB::connectFromEnvironment(), $cuser,$cpw)) { $_SESSION = []; session_destroy(); diff --git a/public/entry/event.php b/public/entry/event.php index aa3f096..f92fbe3 100644 --- a/public/entry/event.php +++ b/public/entry/event.php @@ -23,7 +23,7 @@ function day($in) { return strftime('%A',mktime(12,0,0,4,$in,2001)); } -$pdo = DB::connect(); +$pdo = DB::connectFromEnvironment(); $valid_vars = ['sdesc','ldesc','email','country','category','type','url','sane','smonth','sday','syear','emonth','eday','eyear','recur','recur_day']; foreach($valid_vars as $k) { diff --git a/public/entry/svn-account.php b/public/entry/svn-account.php index 02a9c2b..a5fc997 100644 --- a/public/entry/svn-account.php +++ b/public/entry/svn-account.php @@ -63,7 +63,7 @@ die('Username is too long. It must have 1-16 characters.'); } -$pdo = DB::connect(); +$pdo = DB::connectFromEnvironment(); if (!is_emailable_address($email)) die("that email address does not appear to be valid"); diff --git a/public/entry/user-note.php b/public/entry/user-note.php index b4ec32e..28fba93 100644 --- a/public/entry/user-note.php +++ b/public/entry/user-note.php @@ -56,7 +56,7 @@ function validateUser($user) { unset($note_lc); /* End SPAM Checks ******************************************/ -$pdo = DB::connect(); +$pdo = DB::connectFromEnvironment(); /* After a discussion in #php about the diff --git a/public/entry/user-notes-vote.php b/public/entry/user-notes-vote.php index 10b99f1..fc15513 100644 --- a/public/entry/user-notes-vote.php +++ b/public/entry/user-notes-vote.php @@ -155,7 +155,7 @@ function vote_validate_request(PDO $dbh) { // Initialize global PDO database handle try { - $dbh = DB::connect(); + $dbh = DB::connectFromEnvironment(); } catch(PDOException $e) { $jsonResponse->message = "The server could not complete this request. Please try again later..."; echo json_encode($jsonResponse); diff --git a/public/fetch/allusers.php b/public/fetch/allusers.php index ba4090f..9f01024 100644 --- a/public/fetch/allusers.php +++ b/public/fetch/allusers.php @@ -26,7 +26,7 @@ function error($text, $status) (!isset($_GET['token']) || md5($_GET['token']) != "d3fbcabfcf3648095037175fdeef322f") && error("token not correct.", 401); -$pdo = DB::connect(); +$pdo = DB::connectFromEnvironment(); $stmt = $pdo->prepare("SELECT name, username FROM users WHERE enable AND cvsaccess"); if (!$stmt->execute()) { diff --git a/public/fetch/cvsauth.php b/public/fetch/cvsauth.php index 519d620..f41e1df 100644 --- a/public/fetch/cvsauth.php +++ b/public/fetch/cvsauth.php @@ -85,7 +85,7 @@ function is_valid_cvsauth_token($token) { exit_forbidden(E_UNKNOWN); } -$db = DB::connect(); +$db = DB::connectFromEnvironment(); if (!verify_username($db, $username)) { exit_forbidden(E_USERNAME); } diff --git a/public/fetch/cvsforwarding.php b/public/fetch/cvsforwarding.php index e4fc67f..111259e 100644 --- a/public/fetch/cvsforwarding.php +++ b/public/fetch/cvsforwarding.php @@ -9,7 +9,7 @@ die("token not correct."); // Connect and generate the list from the DB -$pdo = DB::connect(); +$pdo = DB::connectFromEnvironment(); $res = $pdo->safeQuery("SELECT username,email,spamprotect FROM users WHERE email != '' AND cvsaccess"); foreach ($res as $row) { echo "$row[username]@php.net: ", diff --git a/public/fetch/email-aliases.php b/public/fetch/email-aliases.php index 3609cd0..98bdf93 100644 --- a/public/fetch/email-aliases.php +++ b/public/fetch/email-aliases.php @@ -27,7 +27,7 @@ function error($text, $status) // original token defined in ansible vault and in fetch-aliases-from-main.sh script on php-smtp4:~/emailsync (!isset($_GET['token']) || sha1($_GET['token']) != "1789734af16d0fe009375e1f4dbe11e02c5919bc") && error("token not correct.", 401); -$pdo = DB::connect(); +$pdo = DB::connectFromEnvironment(); $stmt = $pdo->prepare("SELECT username, email FROM users WHERE enable = 1 AND email != '' ORDER BY username"); if (!$stmt->execute()) { diff --git a/public/fetch/events.php b/public/fetch/events.php index 71246b6..5fe50bb 100644 --- a/public/fetch/events.php +++ b/public/fetch/events.php @@ -14,7 +14,7 @@ if (!isset($_REQUEST['token']) || md5($_REQUEST['token']) != "19a3ec370affe2d899755f005e5cd90e") die("token not correct."); -$pdo = DB::connect(); +$pdo = DB::connectFromEnvironment(); // Set default values if (!isset($cm)) $cm = (int)strftime('%m'); diff --git a/public/fetch/user-notes-rss.php b/public/fetch/user-notes-rss.php index ea62828..84fec4b 100644 --- a/public/fetch/user-notes-rss.php +++ b/public/fetch/user-notes-rss.php @@ -6,7 +6,7 @@ require_once __DIR__ . '/../../include/functions.inc'; require_once __DIR__ . '/../../vendor/autoload.php'; -$pdo = DB::connect(); +$pdo = DB::connectFromEnvironment(); if (isset($_GET['limit']) && is_numeric($_GET['limit']) && $_GET['limit'] <= 1000) { $limit = $_GET['limit']; diff --git a/public/fetch/user-notes.php b/public/fetch/user-notes.php index 7cc3576..399e129 100644 --- a/public/fetch/user-notes.php +++ b/public/fetch/user-notes.php @@ -8,7 +8,7 @@ if (!isset($_REQUEST['token']) || md5($_REQUEST['token']) != "19a3ec370affe2d899755f005e5cd90e") die("token not correct."); -$dbh = DB::connect(); +$dbh = DB::connectFromEnvironment(); $query = "SELECT DISTINCT note.id,note.sect,note.user,note.note,UNIX_TIMESTAMP(note.ts) AS ts,"; $query .= "SUM(votes.vote) AS up, (COUNT(votes.vote) - SUM(votes.vote)) AS down,"; diff --git a/public/fetch/user-profile.php b/public/fetch/user-profile.php index a5ef9f2..2cfb224 100644 --- a/public/fetch/user-profile.php +++ b/public/fetch/user-profile.php @@ -36,7 +36,7 @@ function render($result) $USERNAME = filter_input(INPUT_GET, "username", FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH); -$pdo = DB::connect(); +$pdo = DB::connectFromEnvironment(); $stmt = $pdo->prepare(" SELECT u.username, COALESCE(up.markdown, '') AS markdown, COALESCE(up.html, '') AS html diff --git a/public/fetch/user.php b/public/fetch/user.php index 2478954..5813abc 100644 --- a/public/fetch/user.php +++ b/public/fetch/user.php @@ -28,7 +28,7 @@ function error($text, $status) $USERNAME = filter_input(INPUT_GET, "username", FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_HIGH); -$pdo = DB::connect(); +$pdo = DB::connectFromEnvironment(); $stmt = $pdo->prepare("SELECT userid, name, email, username, spamprotect, use_sa, greylist, enable FROM users WHERE username = ? AND cvsaccess LIMIT 1"); if (!$stmt->execute([$USERNAME])) { diff --git a/public/forgot.php b/public/forgot.php index 51a9efe..7d68c77 100644 --- a/public/forgot.php +++ b/public/forgot.php @@ -20,7 +20,7 @@ function random_password() { head("forgotten password"); -$pdo = DB::connect(); +$pdo = DB::connectFromEnvironment(); if ($id && $key) { if ($n1 && $n2) { diff --git a/public/github-webhook.php b/public/github-webhook.php index 6224ae6..0afe5b9 100644 --- a/public/github-webhook.php +++ b/public/github-webhook.php @@ -301,7 +301,7 @@ function handle_push_mail($payload) { return; } - $dbh = DB::connect(); + $dbh = DB::connectFromEnvironment(); $pusherName = $payload->pusher->name; foreach ($payload->commits as $commit) { diff --git a/public/manage/event.php b/public/manage/event.php index f56af93..82d09ce 100644 --- a/public/manage/event.php +++ b/public/manage/event.php @@ -28,7 +28,7 @@ $type = [1=>'single',2=>'multi',3=>'recur']; head("event administration"); -$pdo = DB::connect(); +$pdo = DB::connectFromEnvironment(); $id = $_REQUEST['id'] ?? false; $action = $_REQUEST['action'] ?? false; diff --git a/public/manage/user-notes.php b/public/manage/user-notes.php index bdb2bac..91f9a8d 100644 --- a/public/manage/user-notes.php +++ b/public/manage/user-notes.php @@ -38,7 +38,7 @@ Your note has been removed from the online manual.'; -$pdo = DB::connect(); +$pdo = DB::connectFromEnvironment(); $action = (isset($_REQUEST['action']) ? preg_replace('/[^\w\d\s_]/', '', $_REQUEST['action']) : ''); $id = (isset($_REQUEST['id']) ? intval($_REQUEST['id']) : ''); diff --git a/public/manage/users.php b/public/manage/users.php index f40c584..b065434 100644 --- a/public/manage/users.php +++ b/public/manage/users.php @@ -61,7 +61,7 @@ function csrf_validate(&$mydata, $name) { head("user administration"); -$pdo = DB::connect(); +$pdo = DB::connectFromEnvironment(); # ?username=whatever will look up 'whatever' by email or username if ($username) { diff --git a/scripts/email-note-summaries b/scripts/email-note-summaries index 5a03be6..6690d36 100755 --- a/scripts/email-note-summaries +++ b/scripts/email-note-summaries @@ -7,7 +7,7 @@ require_once __DIR__ . '/../vendor/autoload.php'; define('LIMIT', 10); -$pdo = DB::connect(); +$pdo = DB::connectFromEnvironment(); /** --[ pages with most notes ] ------------------- **/ diff --git a/scripts/remove-low-rated-notes b/scripts/remove-low-rated-notes index 3b05b4f..6d31bd5 100755 --- a/scripts/remove-low-rated-notes +++ b/scripts/remove-low-rated-notes @@ -8,7 +8,7 @@ require_once __DIR__ . '/../vendor/autoload.php'; define('RATING_THRESHOLD', "-5"); define('AGE_THRESHOLD', '1 year'); -$pdo = DB::connect(); +$pdo = DB::connectFromEnvironment(); $query = "SELECT COUNT(*) FROM note"; $total = $pdo->single($query); diff --git a/src/DB.php b/src/DB.php index 0309ed6..91a59c0 100644 --- a/src/DB.php +++ b/src/DB.php @@ -6,7 +6,7 @@ final class DB extends PDO { - public static function connect(string $dsn, ?string $username = null, ?string $password = null, ?array $options = null): static + public static function connectFromEnvironment(): static { $connectionConfig = 'mysql:host=' . self::getHost() . ';port=' . self::getPort() . ';dbname=' . self::getDatabase();

« previous php.webmaster (#33718) next »