-3

I'm getting error after writing following code

<?php
$dbname = "localhost";
$dbuser = "root";
$dbpassword = "";
$dbname = "yangi";
$conn = new mysqli($dbname,$dbuser,$dbpassword,$dbname);

if($conn->connect_error){
    die("hatolik".$conn->connect_error);
}else{
    echo("success");
}
?>

Warning: mysqli::__construct(): php_network_getaddresses: getaddrinfo failed: ���� ���� ����������. in C:\xampp\htdocs\Yangi_korinish\inc\Connection.php on line 6

Warning: mysqli::__construct(): (HY000/2002): php_network_getaddresses: getaddrinfo failed: ���� ���� ����������. in C:\xampp\htdocs\Yangi_korinish\inc\Connection.php on line 6 hatolikphp_network_getaddresses: getaddrinfo failed: ���� ���� ����������.

mega6382
  • 9,211
  • 17
  • 48
  • 69
Jahongir Sabirov
  • 460
  • 1
  • 8
  • 24

1 Answers1

1

The problem here is that you used $dbname for the host name and the database name, which is technically being overwritten.

You need to change your code to the following:

$hostname = "localhost";
$dbuser = "root";
$dbpassword = "";
$dbname = "yangi";
$conn = new mysqli($hostname,$dbuser,$dbpassword,$dbname);

Seeing the many , you also have an encoding issue. Make everything to be UTF-8, which also includes the file's encoding.

Note: UTF-8 has a few encoding options. One to contain a BOM (byte order mark) or not. If that fails, you will need to make it "without" the BOM.

References:

If the above statement failed, have a look at the following on Stack:

Which I doubt is a duplicate of this question. I have my money on the wrong hostname variable.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141