0

すべてのデータベース情報 (データベース名、ホスト、ユーザー名、パスワード) を含む一般的な php ファイルが必要です

しかし、index.php のようにページを含めると、次のエラーが発生します。

ユーザー 'apache'@'localhost' のアクセスが拒否されました (パスワードを使用: NO)

connect.php

<?php
class dbconnect{
    private $host = '**'; 
    private $user = '**';
    private $pass = '**';
    public $con;

function Connect($db = '**') {

    if($db=='**'){
        $this->host="localhost";
        $this->user="**";
        $this->pass="**";
        $db="**";
    }else{
                $this->host="**";
                $this->user="**";
                $this->pass="**";
    }

    $this->con = mysql_connect($this->host,$this->user,$this->pass);
    if (!$this->con)
      {
        die('Could not connect: ' . mysql_error());
      }
    $blaa = mysql_select_db($db, $this->con);
    mysql_query("SET NAMES UTF8");
    return $blaa;
}

function Disconnect() {
    //$this->con = mysql_connect($this->host,$this->user,$this->pass);
    mysql_close();
}
}
?>

次のように指定すると、 ** 情報が正しいと確信しています。

$con=mysqli_connect("example.com","example","password","my_db");

index.php で動作します

4

4 に答える 4