title: How to use mysqli connection with SSL
body: <p>I'm trying to make a secure connection with my database</p>
  <p>I wrote the following code:</p>
  <pre><code>&lt;?php
  
  // form filled?
  if (isset($_POST['submit'])) {
      $user = 'gebruiker';
      $pass = 'gebruiker';
      $db = new mysqli('localhost', $user, $pass, 'forum');
      if (mysqli_connect_errno()) {
          echo 'database doesnt work';
          file_put_contents('MySQLiErrors.txt', date('[Y-m-d H:i:s]') .          mysqli_connect_error() . &quot;\r\n&quot;, FILE_APPEND);
          exit();
      } else {
          $username = $_POST['username'];
          $userspassword = $_POST['password'];
          $salt = strrev($userspassword . substr(0, 4));
          $password = hash('sha512', $userspassword . $salt);
          $statement = $db-&gt;prepare(&quot;SELECT id,username FROM user WHERE username = ? AND password = ?&quot;);
          $statement-&gt;bind_param(&quot;ss&quot;, $username, $password);
          $statement-&gt;execute();
          $result = $statement-&gt;get_result();
          $statement-&gt;close();
          $count = $result-&gt;num_rows;
          if ($count &gt; 0) {
              session_start();
              $_SESSION[&quot;username&quot;] = $username;
              header(&quot;Location: forum.php&quot;);
          } else {
              $_SESSION['Error'] = &quot;Invalid username or password&quot;;
          }
      }
      $db-&gt;close();
  }
  </code></pre>
  <p>I also read something about SSL connections on php.net but I don't have any idea how to implement this in this case.</p>
  <p><a href="http://php.net/manual/en/mysqli.ssl-set.php" rel="noreferrer">http://php.net/manual/en/mysqli.ssl-set.php</a></p>
  <p>My code is running on fedora 21 and it works fine but the next thing I want is a secure connection using SSL.</p>