From ec2bb66a68eebad17459e2581d29493aa514b18d Mon Sep 17 00:00:00 2001 From: Fatih20 <fnri39@protonmail.com> Date: Fri, 17 Nov 2023 05:05:45 +0700 Subject: [PATCH] USe proper DB address. --- src/services/CityService.php | 12 ++++++------ src/services/GymService.php | 14 +++++++------- src/services/MultimediaService.php | 6 +++--- src/services/RatingService.php | 12 ++++++------ src/services/UserService.php | 14 +++++++------- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/services/CityService.php b/src/services/CityService.php index f4e775b..0cc4372 100644 --- a/src/services/CityService.php +++ b/src/services/CityService.php @@ -26,7 +26,7 @@ class CityService extends BaseService public function getAll() { - $pdo = new PDO("mysql:host=db;port=3306;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); + $pdo = new PDO("mysql:host=docker-php-db-1;port=3308;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); $query = 'SELECT * FROM city'; $statement = $pdo->prepare($query); $statement->execute(); @@ -52,7 +52,7 @@ class CityService extends BaseService throw new ServiceException(ServiceErrorType::ENTITY_EXIST); } - $pdo = new PDO("mysql:host=db;port=3306;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); + $pdo = new PDO("mysql:host=docker-php-db-1;port=3308;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); $statement = $pdo->prepare("INSERT INTO city VALUES (NULL, :name)"); $statement->bindParam(':name', $name, PDO::PARAM_STR_CHAR); @@ -79,7 +79,7 @@ class CityService extends BaseService throw new ServiceException(ServiceErrorType::ENTITY_EXIST); } - $pdo = new PDO("mysql:host=db;port=3306;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); + $pdo = new PDO("mysql:host=docker-php-db-1;port=3308;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); $statement = $pdo->prepare("UPDATE city SET name = :name WHERE city_id = :city_id"); $statement->bindParam(':name', $newName, PDO::PARAM_STR); @@ -95,7 +95,7 @@ class CityService extends BaseService { $result = null; - $pdo = new PDO("mysql:host=db;port=3306;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); + $pdo = new PDO("mysql:host=docker-php-db-1;port=3308;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); $query = "SELECT * FROM city WHERE name = :city_name"; $statement = $pdo->prepare($query); @@ -118,7 +118,7 @@ class CityService extends BaseService public function getById($city_id): CityModel|null { $result = null; - $pdo = new PDO("mysql:host=db;port=3306;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); + $pdo = new PDO("mysql:host=docker-php-db-1;port=3308;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); $query = "SELECT * FROM city WHERE city_id = :city_id"; $statement = $pdo->prepare($query); @@ -143,7 +143,7 @@ class CityService extends BaseService public function delete($cityId): void { $result = null; - $pdo = new PDO("mysql:host=db;port=3306;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); + $pdo = new PDO("mysql:host=docker-php-db-1;port=3308;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); $query = "DELETE FROM city WHERE city_id = :city_id"; $statement = $pdo->prepare($query); diff --git a/src/services/GymService.php b/src/services/GymService.php index 8548c13..9bc0ce4 100644 --- a/src/services/GymService.php +++ b/src/services/GymService.php @@ -31,7 +31,7 @@ class GymService extends BaseService */ public function getAll() { - $pdo = new PDO("mysql:host=db;port=3306;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); + $pdo = new PDO("mysql:host=docker-php-db-1;port=3308;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); $gyms_raw = $pdo->query("SELECT * FROM gym JOIN (SELECT city_id, name city_name FROM city) AS c ON gym.city_id = c.city_id")->fetchAll(PDO::FETCH_ASSOC); $gyms = []; @@ -55,7 +55,7 @@ class GymService extends BaseService $searching = $filter['searching']; $gymInPageCount = ($filter['gymCountInPage'] ?? 1) <= 0 ? 5 : $filter['gymCountInPage']; - $pdo = new PDO("mysql:host=db;port=3306;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); + $pdo = new PDO("mysql:host=docker-php-db-1;port=3308;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); // Create where clause $whereClause = ""; @@ -173,7 +173,7 @@ class GymService extends BaseService { $result = null; try { - $pdo = new PDO("mysql:host=db;port=3306;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); + $pdo = new PDO("mysql:host=docker-php-db-1;port=3308;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); $query = "SELECT * FROM gym JOIN (SELECT city_id, name city_name FROM city) AS c ON gym.city_id = c.city_id WHERE gym_id = :gym_id"; $statement = $pdo->prepare($query); @@ -206,7 +206,7 @@ class GymService extends BaseService ) { - $pdo = new PDO("mysql:host=db;port=3306;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); + $pdo = new PDO("mysql:host=docker-php-db-1;port=3308;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); $statement = $pdo->prepare("INSERT INTO gym VALUES (NULL, :name, :description, :city_id, :picture_id, :video_id, 0, :monthly_price)"); $statement->bindParam(':name', $name, PDO::PARAM_STR_CHAR); @@ -229,7 +229,7 @@ class GymService extends BaseService { $result = null; try { - $pdo = new PDO("mysql:host=db;port=3306;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); + $pdo = new PDO("mysql:host=docker-php-db-1;port=3308;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); $query = "DELETE FROM gym WHERE gym_id = :gym_id"; $statement = $pdo->prepare($query); @@ -253,7 +253,7 @@ class GymService extends BaseService int $videoId, int $monthlyPrice, ) { - $pdo = new PDO("mysql:host=db;port=3306;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); + $pdo = new PDO("mysql:host=docker-php-db-1;port=3308;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); $query = "UPDATE gym SET name = :name, description = :description, city_id = :city_id, picture_id = :picture_id, video_id = :video_id, monthly_price = :monthly_price WHERE gym_id = :gym_id"; @@ -274,7 +274,7 @@ class GymService extends BaseService public function updateRating($gymId) { try { - $pdo = new PDO("mysql:host=db;port=3306;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); + $pdo = new PDO("mysql:host=docker-php-db-1;port=3308;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); // check if the rating is not empty $query = "SELECT * FROM ratings WHERE gym_id = :gym_id"; diff --git a/src/services/MultimediaService.php b/src/services/MultimediaService.php index bf4aa77..385fbdb 100644 --- a/src/services/MultimediaService.php +++ b/src/services/MultimediaService.php @@ -28,7 +28,7 @@ class MultimediaService extends BaseService { $result = null; - $pdo = new PDO("mysql:host=db;port=3306;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); + $pdo = new PDO("mysql:host=docker-php-db-1;port=3308;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); $query = "INSERT INTO `video` (`video_id`) VALUES (NULL);"; $statement = $pdo->prepare($query); @@ -56,7 +56,7 @@ class MultimediaService extends BaseService public function addPicture($pictureFile): int { $result = null; - $pdo = new PDO("mysql:host=db;port=3306;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); + $pdo = new PDO("mysql:host=docker-php-db-1;port=3308;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); $query = "INSERT INTO `picture` (`picture_id`) VALUES (NULL);"; $statement = $pdo->prepare($query); @@ -85,7 +85,7 @@ class MultimediaService extends BaseService { $result = null; try { - $pdo = new PDO("mysql:host=db;port=3306;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); + $pdo = new PDO("mysql:host=docker-php-db-1;port=3308;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); $query = `DELETE FROM city WHERE city_id = :city_id`; $statement = $pdo->prepare($query); diff --git a/src/services/RatingService.php b/src/services/RatingService.php index 704e0a1..d9b5759 100644 --- a/src/services/RatingService.php +++ b/src/services/RatingService.php @@ -32,7 +32,7 @@ class RatingService extends BaseService { $result = null; try { - $pdo = new PDO("mysql:host=db;port=3306;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); + $pdo = new PDO("mysql:host=docker-php-db-1;port=3308;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); $query = "SELECT * FROM ratings WHERE gym_id = :gym_id"; $statement = $pdo->prepare($query); @@ -57,7 +57,7 @@ class RatingService extends BaseService { $result = null; try { - $pdo = new PDO("mysql:host=db;port=3306;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); + $pdo = new PDO("mysql:host=docker-php-db-1;port=3308;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); $username = UserService::getInstance()->getUsername(); @@ -86,7 +86,7 @@ class RatingService extends BaseService public function getRating(int $gymId, string $username): RatingModel|null { $result = null; - $pdo = new PDO("mysql:host=db;port=3306;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); + $pdo = new PDO("mysql:host=docker-php-db-1;port=3308;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); $query = "SELECT * FROM ratings WHERE gym_id = :gym_id AND username = :username"; $statement = $pdo->prepare($query); @@ -114,7 +114,7 @@ class RatingService extends BaseService $result = null; try { - $pdo = new PDO("mysql:host=db;port=3306;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); + $pdo = new PDO("mysql:host=docker-php-db-1;port=3308;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); $query = "INSERT INTO ratings VALUES(:username, :gym_id, :new_rating) ON DUPLICATE KEY UPDATE rating = :new_rating"; $statement = $pdo->prepare($query); @@ -147,7 +147,7 @@ class RatingService extends BaseService $result = null; try { - $pdo = new PDO("mysql:host=db;port=3306;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); + $pdo = new PDO("mysql:host=docker-php-db-1;port=3308;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); $query = "UPDATE ratings SET rating = :new_rating WHERE gym_id = :gym_id AND username = :username"; $statement = $pdo->prepare($query); @@ -179,7 +179,7 @@ class RatingService extends BaseService $result = null; try { - $pdo = new PDO("mysql:host=db;port=3306;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); + $pdo = new PDO("mysql:host=docker-php-db-1;port=3308;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); $query = "DELETE FROM ratings WHERE gym_id = :gym_id AND username = :username"; $statement = $pdo->prepare($query); diff --git a/src/services/UserService.php b/src/services/UserService.php index 193109f..d7d2a66 100644 --- a/src/services/UserService.php +++ b/src/services/UserService.php @@ -31,7 +31,7 @@ class UserService extends BaseService */ public function getAll() { - $pdo = new PDO("mysql:host=db;port=3306;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); + $pdo = new PDO("mysql:host=docker-php-db-1;port=3308;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); $statement = $pdo->prepare("SELECT * FROM user"); $users_raw = $statement->fetchAll(PDO::FETCH_ASSOC); @@ -49,7 +49,7 @@ class UserService extends BaseService { $result = null; try { - $pdo = new PDO("mysql:host=db;port=3306;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); + $pdo = new PDO("mysql:host=docker-php-db-1;port=3308;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); $query = "SELECT username, name, is_admin, city_id FROM user WHERE username = :username"; $statement = $pdo->prepare($query); @@ -90,7 +90,7 @@ class UserService extends BaseService throw new ServiceException(ServiceErrorType::ENTITY_EXIST); } - $pdo = new PDO("mysql:host=db;port=3306;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); + $pdo = new PDO("mysql:host=docker-php-db-1;port=3308;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); $query = "INSERT INTO user (username, password, is_admin, name, city_id) VALUES (:username, :password, 0, :name, :city_id)"; $statement = $pdo->prepare($query); @@ -119,7 +119,7 @@ class UserService extends BaseService public function login($username, $password): UserModel { - $pdo = new PDO("mysql:host=db;port=3306;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); + $pdo = new PDO("mysql:host=docker-php-db-1;port=3308;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); $query = "SELECT username, password, is_admin FROM user WHERE username = :username"; $statement = $pdo->prepare($query); $statement->bindParam(':username', $username, PDO::PARAM_STR); @@ -136,7 +136,7 @@ class UserService extends BaseService $_SESSION['is_admin'] = $result_raw['is_admin']; return $this->getByUsername($username); } else if ($result_raw['password'] != $password) { - throw new ServiceException(ServiceErrorType::PASSWORD_INCORRECT); + throw new ServiceException(ServiceErrorType::PASSWORD_INCORRECT); } else { throw new ServiceException(ServiceErrorType::SOMETHING_WENT_WRONG); } @@ -198,7 +198,7 @@ class UserService extends BaseService throw new ServiceException(ServiceErrorType::ENTITY_EXIST); } - $pdo = new PDO("mysql:host=db;port=3306;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); + $pdo = new PDO("mysql:host=docker-php-db-1;port=3308;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); $query = "UPDATE user SET username = :username, name = :name, city_id = :city_id WHERE username = :old_username"; @@ -232,7 +232,7 @@ class UserService extends BaseService public function delete($username) { $result = null; - $pdo = new PDO("mysql:host=db;port=3306;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); + $pdo = new PDO("mysql:host=docker-php-db-1;port=3308;dbname=gym_tracker", $_ENV['DB_USER'], $_ENV['DB_PASSWORD']); $query = "DELETE FROM user WHERE username = :username"; $statement = $pdo->prepare($query); -- GitLab