title: Should we ever check for mysqli_connect() errors manually?
body: <p>The PHP manual for <a href="https://www.php.net/manual/en/function.mysqli-connect.php" rel="noreferrer"><code>mysqli_connect()</code></a> suggests checking for the return value and displaying the error messages on the screen.</p>
  
  <pre><code>$link = mysqli_connect("127.0.0.1", "my_user", "my_password", "my_db");
  if (!$link) {
      echo "Error: Unable to connect to MySQL." . PHP_EOL;
      echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL;
      echo "Debugging error: " . mysqli_connect_error() . PHP_EOL;
      exit;
  }
  </code></pre>
  
  <p>Similarly for OOP-style constructor this is suggested:</p>
  
  <pre><code>$mysqli = new mysqli('localhost', 'my_user', 'my_password', 'my_db');
  if ($mysqli-&gt;connect_error) {
      die('Connect Error (' . $mysqli-&gt;connect_errno . ') '
              . $mysqli-&gt;connect_error);
  }
  </code></pre>
  
  <p>Some users on Stack Overflow even used code with <code>mysqli_error($conn)</code> such as this:</p>
  
  <pre><code>$conn = mysqli_connect('localhost', 'a', 'a');
  if (!$con) {
      die('Could not connect: ' . mysqli_error($conn));
  }
  </code></pre>
  
  <p>However, in the past few weeks I have been asking myself a question, why would I need to do that? The output of the first example is:</p>
  
  <blockquote>
    <p>Warning:  mysqli_connect(): (HY000/1045): Access denied for user
    'my_user'@'localhost' (using password: YES) in
    C:\xampp\...\mysqli.php on line 4</p>
    
    <p>Error: Unable to connect to MySQL. Debugging errno: 1045 Debugging
    error: Access denied for user 'my_user'@'localhost' (using password:
    YES)</p>
  </blockquote>
  
  <p>As you can see the error message is displayed twice! The manual "debugging" actually provides less information. </p>
  
  <p>Should we ever manually check for connection errors? Would we ever get more information this way than from the automatic warning? Is this the recommended practice?  </p>