Files
tsd_test/www/first.loc/api/mysql_api/Class/Database.php
2026-03-25 13:51:25 +00:00

32 lines
773 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?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;
}
}