2017-04-17 3 views
0

데이터베이스에 연결할 수 없어 그 이유를 모르겠습니다.데이터베이스 연결 문제

저는 php checker에서 오류없이 PHP를 실행했습니다.

나는 온라인 코스를보고 편지에 대한 지침을 따르고 있지만 테스트를하고 작동하는지 확인하려고 할 때 'http 500 오류'가 표시됩니다. Heres는

내 PHP :

; Connection information 
[section] 
dbhost = omitted 
dbuser = omitted 
dbpass = omitted 
dbname = omitted 

그리고 마지막으로이 내 PHP 파일입니다 : 여기

<?php 

//STEP 1. Declare params of user information 
$email = htmlentities($_REQUEST["email"]); 
$password = htmlentities($_REQUEST["password"]); 

$test = "test"; 

if (empty($email) || empty($password)) { 

    $returnArray["status"] = "400"; 
    $returnArray["message"] = "Missing required information"; 
    echo json_encode($returnArray); 
    return; 
    } 

//secure password 
$salt = openssl_random_pseudo_bytes(20); 
$secured_password = sha1($password . $salt); 

//build connection 
//secure way to build connection 
$file = parse_ini_file("../caps.ini"); 

//store in php var info from ini var 
$host = trim($file["dbhost"]); 
$user = trim($file["dbuser"]); 
$pass = trim($file["dbpass"]); 
$name = trim($file["dbname"]); 


// include access.php to call func from access.php file 
require("secure/access.php"); 
$access = new access($host, $user, $pass, $name); 
$access->connect(); 

?> 

그리고 내가 텍스트 편집기에서 만든 caps.ini 파일, 나는 여기에 정보를 생략 한 내 연결 기능을 참조하는 곳 :

<?php 

//Declare class to access this php file 
class access { 

    //connection global variables 
    var $host = null; 
    var $user = null; 
    var $pass = null; 
    var $name = null; 
    var $conn = null; 
    var $result = null; 

    // constructing class 
    function __construct($dbhost, $dbuser, $dbpass, $dbname) { 

    $this->host = $dbhost; 
    $this->user = $dbuser; 
    $this->pass = $dbpass; 
    $this->name = $dbname; 

    } 

    // Connection Function 
    public function connect() { 

     //establish connection and store it in $conn 
     $this->conn = new msqli($this->host, $this->user, $this->pass, $this->name); 

     //if error 
     if (mysqli_connect_errno()) { 
      echo 'Could not connect to database'; 
     } else { 
      echo "Connected"; 
     } 
     //support all languages 
     $this->conn->set_charset("utf8"); 

    } 

    //disconnection function 
    public function disconnect() { 

     if ($this->conn != null) { 
     $this->conn->close(); 
     } 

    } 


} 

다음은 내 폴더 구조입니다.

enter image description here

+1

을해야 mysqli

$this->conn = new msqli($this->host, $this->user, $this->pass, $this->name); 

msqli 주변이 오타입니다; 이어 die(); 문제가 발생한 곳을 찾을 때까지 페이지 상단에 놓고 아래로 이동하십시오. – Radmation

+1

다른 클라이언트로 데이터베이스 서버에 연결할 수 있습니까? 또한 새로운 msqli ('옳지 않은 것, perhapps는 당신이 에러 리포팅을 사용할 수있는 새로운 mysqli (')를 의미한다. – Scuzzy

+0

서버상의 첫번째 파일의 경로는 무엇인가? 그 안에 – Radmation

답변

1

내 가정은 내가 "여기"에코 같은 것을 echo'ing 시도 할 것이다 당신의 PHP에서

$this->conn = new mysqli($this->host, $this->user, $this->pass, $this->name); 
+0

그게 전부입니다. 감사! –

관련 문제