From 56c198cf8707132ec9a75c85cc9e88b467368e8a Mon Sep 17 00:00:00 2001 From: Mischa Braam Date: Sat, 16 Nov 2024 12:07:40 +0100 Subject: [PATCH] Prevent crash on install with wrong DB password --- cli/ValetPlus/Mysql.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/cli/ValetPlus/Mysql.php b/cli/ValetPlus/Mysql.php index 7e32a737..f5f00c2a 100644 --- a/cli/ValetPlus/Mysql.php +++ b/cli/ValetPlus/Mysql.php @@ -5,6 +5,7 @@ namespace WeProvide\ValetPlus; use DomainException; +use Exception; use mysqli; use Valet\Brew; use Valet\CommandLine; @@ -273,17 +274,21 @@ public function listDatabases() */ public function getConnection($withoutRootPwd = false) { - // if connection already exists return it early. + // If connection already exists return it early. if ($this->link) { return $this->link; } // Create connection - $rootPwd = ($withoutRootPwd ? null : $this->getConfigRootPassword()); - $this->link = new mysqli('127.0.0.1', 'root', $rootPwd); + $rootPwd = ($withoutRootPwd ? null : $this->getConfigRootPassword()); + try { + $this->link = new mysqli('127.0.0.1', 'root', $rootPwd); + } catch (Exception $e) { + $this->link = null; + } // Check connection - if ($this->link->connect_error) { + if (!$this->link || $this->link->connect_error) { warning('Failed to connect to database'); return false;