Skip to main content

Database connection using mySQLi with object-oriented

  • 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