我想知道如果我只是包含它们,这两个类是否允许我建立与我的数据库的连接。这些是类:
的 DBconn.php
<?php
class DBconn {
protected $dbname;
protected $dbuser;
protected $dbpassword;
protected $dbhost;
protected $connection;
public function __construct($dbhost, $dbname, $dbuser, $dbpass)
{
$this->dbname = $dbname;
$this->dbhost = $dbhost;
$this->dbuser = $dbuser;
$this->dbpass = $dbpass;
$this->connect();
}
public function getConnection()
{
return $this->connection;
}
protected function connect()
{
$this->connection = new PDO("mysql:host={$this->dbhost};dbname={$this->dbname}", $this->dbuser, $this->dbpass);
}
}
?>
的 dblogin.php
<?php
$db = new DBconn('localhost','phpproject','carl','pdt1848?')
?>