Hasan Setiawan

Write, write, write give your wings on code!

Follow me on GitHub

PHP 7 mysqli connect

MySQL extension has been in PHP core from the very early 2.0 version - it was over 15 years old. One of the main reasons for removal was difficult and complicated maintenance in the PHP core. MySQL extension also doesn't provide all the latest features and benefits of the MySQL database.

      
          $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;
          }

          echo "Success: A proper connection to MySQL was made! The my_db database is great." . PHP_EOL;
          echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL;

          mysqli_close($link);