skip to Main Content

This is my very first time uploading a website. now I’m having a problem with my hosting which is CPANEL.

I’m using the code

<?php
date_default_timezone_set("Asia/Manila");

$servername = "localhost";
$username = "root";
$password = "";
$db = "exampledb";


// Create connection
$conn = new mysqli($servername, $username, $password,$db);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

?>

for my database connection.

Now my problem is what code should I put in servername? instead of localhost?
and same to the username root and password?

2

Answers


  1. On the hosting site in cpanel they normally give you the server name that you can use, the password you will need to create a db user also on cpanel, this will be your user name and password.

    Login or Signup to reply.
  2. // localhost is fine or else you need to keep your server IP.you can find in cpanel.
    $servername = "localhost";
    
    // if you are using database in some other server you should provide IP
    // you need to create a user with required privileges then need to provide username/password 
    // root also fine but better create a user
    $username = "root";
    $password = "";
    
    // Here you need to mention which DB you want use for your application.
    $db = "exampledb";
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search