我想使用連接到數據庫,但是我得到這個錯誤,我在php終端上運行這個。php oop pdo連接被拒絕?
我檢查了其他的來源是這樣one,但沒有我一直在尋找
任何建議或最佳實踐的答案嗎?
db.php中
<?php
error_reporting(-1);
class Db{
private $db_host;
private $db_user;
private $db_name;
private $db_pass;
public function __construct()
{
$this->db_host = "127.0.0.1";
$this->db_user = "root";
$this->db_pass = "";
$this->db_name = "eli9";
try{
$pdo = new PDO("mysql:host=127.0.0.1;dbname=eli9", $this->db_user, $this->db_pass);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "connected sucessfully \n";
}
catch(PDOexception $e){
echo $e->getMessage();
echo "something went wrong \n";
}
}
}
的index.php
<?php
require_once 'Db.php';
$db = new Db();
仍然沒有工作 – BARNOWL
嘗試,現在,希望工程這個時候 – skunkhaze
感謝,但仍然沒有工作,我最近更新到PHP 7我使用5.1 – BARNOWL