PHP - Conexión BDD error

 
Vista:

Conexión BDD error

Publicado por Mauro Sánchez (1 intervención) el 23/03/2016 21:05:04
Buenas tardes a ver quien me puede ayudar ya que tengo el siguiente error.

Ya lo he revisado varias veces y no se porque sale este error.

Notice: Use of undefined constant DB_HOST - assumed 'DB_HOST' in C:\SULPI\System\PROYECTO\Aplicacion\Database.php on line 7

Notice: Use of undefined constant DB_NAME - assumed 'DB_NAME' in C:\SULPI\System\PROYECTO\Aplicacion\Database.php on line 8

Notice: Use of undefined constant DB_USER - assumed 'DB_USER' in C:\SULPI\System\PROYECTO\Aplicacion\Database.php on line 9

Notice: Use of undefined constant DB_PASS - assumed 'DB_PASS' in C:\SULPI\System\PROYECTO\Aplicacion\Database.php on line 10

Notice: Use of undefined constant DB_CHAR - assumed 'DB_CHAR' in C:\SULPI\System\PROYECTO\Aplicacion\Database.php on line 13

Warning: PDO::__construct(): php_network_getaddresses: getaddrinfo failed: Host desconocido. in C:\SULPI\System\PROYECTO\Aplicacion\Database.php on line 13
SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: Host desconocido.

Archivo Configuracion.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php
 
define('BASE_URL', 'http://localhost:83/System/PROYECTO/');
define('DEFAULT_CONTROLLER', 'index');
define('DEFAULT_LAYOUT', 'default');
 
define('APP_NAME', 'FREMEWORK');
define('APP_SLOGAN', 'SULPI');
define('APP_COMPANY', 'www.lamar.edu.mx');
 
define('BD_HOST', 'localhost');
define('BD_USER', 'root');
define('BD_PASS', '');
define('BD_NAME', '_universidadlamar');
define('BD_CHAR', 'utf8');
 
?>


Archivo 2 Database.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php
 
class Database extends PDO
{
    public function __construct() {
        parent::__construct(
                'mysql:host=' . DB_HOST .
                ';dbname=' . DB_NAME,
                DB_USER,
                DB_PASS,
                array(
                    PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES ' . DB_CHAR
                    ));
 
    }
}
 
 
?>
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Max

Conexión BDD error

Publicado por Max (19 intervenciones) el 24/03/2016 17:18:25
He localizado el error a simple vista, simple y llanamente has nombrado mal las constantes así que al llamarlas (de la manera que se supone deberían llamarse) el interprete de PHP te dice que no existen.

Reemplaza esto:

1
2
3
4
5
define('BD_HOST', 'localhost');
define('BD_USER', 'root');
define('BD_PASS', '');
define('BD_NAME', '_universidadlamar');
define('BD_CHAR', 'utf8');

Por esto:

1
2
3
4
5
define('DB_HOST', 'localhost');
define('DB_USER', 'root');
define('DB_PASS', '');
define('DB_NAME', '_universidadlamar');
define('DB_CHAR', 'utf8');

Si hay o no otro error en tu código no lo detecto, (ya que nunca me he visto en la necesidad de usar PDO), eso sí, te recomiendo aprender a leer los errores que te provee el interprete de PHP ya que te evitarás perder la cabeza con algo tan sencillo como esto. Saludos.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar