0
データベースに接続できず、その理由を理解できません。データベース接続の問題
私はエラーなしでphpチェッカーで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();
}
}
}
ここに私のフォルダ構造もあります:
である必要があり、私は "ここに" のエコーのようなものをecho'ingしようと
msqli
mysqli
対の周りにこのタイプミスです。続いてdie();問題が発生している場所を見つけるまでページの上部に置き、下に移動します。 – Radmation
別のクライアントでデータベースサーバに接続できますか?また、 'new msqli('正しく表示されません、perhappsはあなたがエラー報告機能を有効にして見つけた '新しいmysqli(')を意味します) – Scuzzy
サーバ上の最初のファイルのパスは何ですか?それは – Radmation