Database connection using mySQLi with object-oriented

Updated at 12-Jan-2021, By samar

Database connection using mySQLi with object-oriented

In this session, we’ll try our hand at solving the "Database connection using mySQLi with object-oriented" puzzle by using the computer language.

  • Database connection using mysqli in php

    $servername = "localhost";
    $username = "root";
    $password = "";
    $dbname = "myproject_db";
    
    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);
    
    // Check connection
    if ($conn->connect_error) {
      die("Connection failed: " . $conn->connect_error);
    }
    

    You have to provide your server, username, password, and database name to connect the database.

Back to code snippet queries related sql