MySQLi Connect OOP

    0

    2

    mysqli_connect

    This code is setting up a connection to the MySQL database. If there is an error connecting to the database, an error message will be displayed and the program will exit.

    Shortcut: mysqli_connect

    <?php
      
    // MySQli connection
    $mysqli = new mysqli("localhost","user","password","db");
    
    // Check connection
    if ($mysqli -> connect_errno) {
      echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
      exit();
    }
    
    ?>
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.