Error mysqli_connect (): (HY000 / 2002): php_network_getaddresses: getaddrinfo failed: Unknown host

0

I am in my first steps of programming in PHP and I find this error .

This is my configuration file

This is my connection file

This is the error that comes to me in the navigator.

Warning: mysqli_connect(): php_network_getaddresses: getaddrinfo failed: 
 Host desconocido. in C:\xampp\htdocs\sistema\config\Conexion.php on 
 line 4

 Warning: mysqli_connect(): (HY000/2002): php_network_getaddresses: 
 getaddrinfo failed: Host desconocido. in 
 C:\xampp\htdocs\sistema\config\Conexion.php on line 4

Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given 
in C:\xampp\htdocs\sistema\config\Conexion.php on line 7
Falló la conexión a la base de datos: php_network_getaddresses: getaddrinfo 
failed: Host desconocido.

Database server

  • Server: 127.0.0.1 via TCP / IP

  • Server type: MariaDB

  • Server version: 10.1.28-MariaDB - mariadb.org binary distribution

  • Protocol version: 10

  • User: root @ localhost

  • Server character set: UTF-8 Unicode (utf8)

Web server

  • Apache / 2.4.29 (Win32) OpenSSL / 1.0.2l PHP / 7.1.11

  • Database client version: libmysql - mysqlnd 5.0.12-dev - 20150407 $ Id: b396954eeb2d1d9ed7902b8bae237b287f21ad9e $

  • PHP extension: mysqliDocumentation curlMbstring documentationDocumentation PHP version: 7.1.11

Operating System Windows 10

    
asked by jrlopezd 15.12.2017 в 03:05
source

1 answer

1

When you write this:

define ("DB_HOST", "localhost");

You are defining a constant that is called DB_HOST , whose value is localhost .

When the time comes to use the value of that constant, you should use it without quotes, since if you use quotes you will never get the value localhost but a string in quotes.

Doing that in your current code, what you're saying is that the host is called "DB_HOST" ... The same thing happens with the other constants. Then, the names of the defined constants are passed to the constructor, without quotes:

$conexion=new mysqli (DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME);

For more details, you can consult the documentation about define in the PHP Manual . In Example # 1 the constant is used as explained in this answer.

    
answered by 15.12.2017 в 05:23