본문 바로가기
MySql

MySQL error connecting to MYSQL

by 베이스 공부 2021. 2. 5.
반응형

다음은 config.php 파일입니다.

<?php

error_reporting(E_ALL ^ E_NOTICE);

/*=========== Database Configuraiton ==========*/

$db_host = "localhost";
$db_user = "test";
$db_pass = "test";
$db_name = "dbtest";


/*=========== Website Configuration ==========*/

$defaultTitle = 'testing';
$defaultFooter = date('Y').' &copy; testing';

?>

다음은 config.php에 대한 참조입니다.

<?php


require_once "includes/config.php";
require_once "includes/connect.php";
require_once "includes/helpers.php";



header('Cache-Control: max-age=3600, public');
header('Pragma: cache');
header("Last-Modified: ".gmdate("D, d M Y H:i:s",time())." GMT");
header("Expires: ".gmdate("D, d M Y H:i:s",time()+3600)." GMT");

?>

Connect.php는 다음과 같습니다.

<?php

/*
        The login details are taken from config.php.
*/

try {
    $db = new PDO(
        "mysql:host=$db_host;dbname=$db_name;charset=UTF-8",
        $db_user,
        $db_pass
    );

    $db->query("SET NAMES 'utf8'");
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch(PDOException $e) {
    error_log($e->getMessage());
    die("A database error was encountered");
}


?>

이 코드에 문제가있는 사람이 있습니까? connect.php에서 "데이터베이스 오류가 발생했습니다"라는 오류 메시지가 나타납니다. 모든 정보가 정확 해 보이고 코드에서 오류를 볼 수 없기 때문에 다른 눈이 필요합니다. 감사.

 

해결 방법

 

변수로 사용하는 대신 자격 증명을 직접 사용해보십시오.

또한 아래를 사용하여 디버깅을 시도하십시오.

catch(PDOException $e) {
    error_log($e->getMessage());
    die("A database error was encountered -> " . $e->getMessage() );
}

작동하는지 알려주세요.

 

참조 페이지 https://stackoverflow.com/questions/11475365

 

 

반응형

댓글