c1
This commit is contained in:
31
www/first.loc/api/mysql_api/Class/Database.php
Normal file
31
www/first.loc/api/mysql_api/Class/Database.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
// Используем для подключения к базе данных MySQL
|
||||
class Database
|
||||
{
|
||||
// Учётные данные базы данных
|
||||
private $host = "mysql:3306";
|
||||
public $db_name = "tsd";
|
||||
private $username = "tsduser";
|
||||
|
||||
private $password = "sdWs@a201!";
|
||||
// private $username = "root";
|
||||
|
||||
// private $password = "secret";
|
||||
|
||||
public $conn;
|
||||
|
||||
// Получаем соединение с базой данных
|
||||
public function getConnection()
|
||||
{
|
||||
$this->conn = null;
|
||||
|
||||
try {
|
||||
$this->conn = new PDO("mysql:host=" . $this->host . ";dbname=" . $this->db_name.";charset=UTF8", $this->username, $this->password);
|
||||
} catch (PDOException $exception) {
|
||||
echo "Ошибка соединения с БД: " . $exception->getMessage();
|
||||
}
|
||||
|
||||
return $this->conn;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user