2017-04-17 159 views
0

我无法连接到我的数据库,我不明白为什么。数据库连接问题

我已经在没有错误的php检查器中运行我的php。

我正在看一个在线课程,并按照该信的说明,但当我尝试测试并查看它是否有效时,我收到'http 500错误'。

继承人我的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文件我在文本编辑器中进行,我省略了这里的信息:

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

最后,这是我的PHP文件我参考了我的连接功能:

<?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

在你的PHP我会尝试echo'ing像回声 “这里”;其次是die();并将其放在页面顶部并将其向下移动,直到找到问题出现的位置。 – Radmation

+1

您可以使用其他客户端连接到数据库服务器吗?也'新msqli('不看的权利,perhapps你的意思是'新的mysqli('你会启用错误报告中。 – Scuzzy

+0

什么是你的第一个文件的服务器上的路径?用'//步骤1'文件在它 – Radmation

回答

1

我的假设是围绕msqli这个错字VS mysqli

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

应该

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

这是它。谢谢! –