Skip to content

Commit

Permalink
Prevent crash on install with wrong DB password
Browse files Browse the repository at this point in the history
  • Loading branch information
mischabraam committed Nov 16, 2024
1 parent 600a33a commit 56c198c
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions cli/ValetPlus/Mysql.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace WeProvide\ValetPlus;

use DomainException;
use Exception;
use mysqli;
use Valet\Brew;
use Valet\CommandLine;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 56c198c

Please sign in to comment.