rockwood
Members-
Posts
452 -
Joined
-
Last visited
-
Days Won
17
Content Type
Profiles
Forums
Events
Everything posted by rockwood
-
Ah okay
-
I am very surprised that we are still using this kind of global variable in 2024. Why aren't we considering dependency injection? For Example: <?php // Define a Database Connection interface interface DatabaseConnectionInterface { public function connect(): PDO; } // Implement the Database Connection using PDO class DatabaseConnection implements DatabaseConnectionInterface { private string $host; private string $db; private string $user; private string $pass; public function __construct(string $host, string $db, string $user, string $pass) { $this->host = $host; $this->db = $db; $this->user = $user; $this->pass = $pass; } public function connect(): PDO { try { return new PDO("mysql:host={$this->host};dbname={$this->db}", $this->user, $this->pass); } catch (PDOException $e) { throw new Exception("Database connection error: " . $e->getMessage()); } } } // Define a User Repository that uses the Database Connection class UserRepository { private DatabaseConnectionInterface $dbConnection; // Constructor injection of the Database Connection public function __construct(DatabaseConnectionInterface $dbConnection) { $this->dbConnection = $dbConnection; } public function findUserById(int $id): ?array { $pdo = $this->dbConnection->connect(); $stmt = $pdo->prepare("SELECT * FROM users WHERE id = :id"); $stmt->execute(['id' => $id]); return $stmt->fetch(PDO::FETCH_ASSOC); } public function createUser(string $username, string $email): void { $pdo = $this->dbConnection->connect(); $stmt = $pdo->prepare("INSERT INTO users (username, email) VALUES (:username, :email)"); $stmt->execute(['username' => $username, 'email' => $email]); } } // Client code to use the repository function main() { // Database credentials $host = 'localhost'; $db = 'your_database'; $user = 'your_username'; $pass = 'your_password'; // Create a Database Connection instance $dbConnection = new DatabaseConnection($host, $db, $user, $pass); // Inject the Database Connection into UserRepository $userRepository = new UserRepository($dbConnection); // Example: Create a new user $userRepository->createUser('john_doe', '[email protected]'); // Example: Find a user by ID $user = $userRepository->findUserById(1); print_r($user); } // Run the main function main();
-
-
Xampp is outdated technology you can move on wsl2
-
i can do
-
use appropriate background with suitable animation for make it better in my opinion do you remember criminalimpulse game? Significant improvement is needed here. Using $global is not a good idea; it's better to use Dependency Injection (DI).
-
I am 41 now me too love build something
-
Introducing Gladiateurs Battle - A Strategic Turn-Based Combat Game!
rockwood replied to HanGPIErr's topic in Game Projects
lovely work -
Introducing Gladiateurs Battle - A Strategic Turn-Based Combat Game!
rockwood replied to HanGPIErr's topic in Game Projects
What did you use to create this? -
yes
-
https://gitlab.com/Magictallguy/grpg-pdo/-/blob/master/inc/Zebra_Session.php?ref_type=heads if (!empty($this->flashdata)) { <-- no need this bcz foreach care itself for example -> https://3v4l.org/PqKPM
-
What is Dayo new sute name?
-
Nice we are still alive
-
What is web3 game?
-
Hope this journey never endup š
-
Congratz
-
mccode-v2 Change the bank interest without crons?
rockwood replied to MajikalJoker's topic in Requests & In Production
window.onload = function() { // Call your function immediately if needed executeQuery(); // Then set it to run every 5 minutes setInterval(function() { executeQuery(); }, 300000); // 300000 milliseconds = 5 minutes }; function executeQuery() { console.log("Query executed at: " + new Date().toLocaleTimeString()); // Your query or code goes here } -
Im Back. Creating a new adventure. Future based game.
rockwood replied to EliteNoob's topic in Gangster Legends
no game on BW-Codes.com. the message is showing on : Main template 'NewYorkMafia' file not found! -
Me too wanna help in testing let me in plz
-
Today i am unable to login in your game.
-
Hire any developer then
-
Many AI out of box for image generation.
-
š Join the Beta of AgeOfSpace: A New Era of Space Strategy Awaits!
rockwood replied to AgeOfSpaceGame's topic in General
i am impressed