Created
March 5, 2025 07:29
-
-
Save mhmtsnmzkanly/9f104c764fda8135fbd7d267af6d3193 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (!Defined("ROYAL")) | |
exit(); | |
class Royal | |
{ | |
private PDO $connection; | |
public function __construct(array $config) | |
{ | |
try { | |
$this->connection = new PDO('mysql:host=' . $config["db"]["host"] . ';dbname=' . $config["db"]["db"], $config["db"]["username"], $config["db"]["password"]); | |
$this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); | |
} catch (PDOException $e) { | |
print_r($e); | |
exit; | |
} | |
} | |
public function db(): PDO | |
{ | |
return $this->connection; | |
} | |
public function Query(string $query) | |
{ | |
return $this->connection->query($query); | |
} | |
public function Prepare(string $query) | |
{ | |
return $this->connection->prepare($query); | |
} | |
public function Execute(string $query, array $params = []) | |
{ | |
try { | |
$statement = $this->Prepare($query); | |
$statement->execute($params); | |
return $statement; | |
} catch (PDOException $e) { | |
print_r($e); | |
exit; | |
} | |
} | |
} | |
$Royal = new Royal([ | |
"db" => [ | |
"host" => "localhost", | |
"username" => "root", | |
"password" => "", | |
"db" => "royal" | |
] | |
]); | |
$LinkList = $Royal->Execute("SELECT * FROM links WHERE is_active = '1'")->fetchAll(PDO::FETCH_OBJ); | |
$getUserQuery = $Royal->Prepare("SELECT * FROM users WHERE username = :un"); | |
$getUserQuery->bindParam(":un", $un, PDO::PARAM_STR); | |
$getUserQuery->execute(); | |
$user = $getUserQuery->fetch(PDO::FETCH_OBJ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment