Jump to content
MakeWebGames

rockwood

Members
  • Posts

    452
  • Joined

  • Last visited

  • Days Won

    17

Everything posted by rockwood

  1. Ah okay
  2. 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();
  3. I’m also working on coding a game, but I’m making slow rogress and feeling quite sluggish. šŸ™‚
  4. Xampp is outdated technology you can move on wsl2
  5. Ah okay.
  6. 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).
  7. I am 41 now me too love build something
  8. it will be gr8
  9. 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
  10. What is Dayo new sute name?
  11. Nice we are still alive
  12. What is web3 game?
  13. Hope this journey never endup šŸ™‚
  14. 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 }
  15. no game on BW-Codes.com. the message is showing on : Main template 'NewYorkMafia' file not found!
  16. Me too wanna help in testing let me in plz
  17. Today i am unable to login in your game.
  18. Hire any developer then
  19. Many AI out of box for image generation.
×
×
  • Create New...