Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Database{
- public $isConn;
- protected $data;
- public function __construct($username = "root", $password = "", $host = "127.0.0.1", $dbname = "test", $options = []){
- $this->isConn = TRUE;
- $this->data = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8", $username, $password, $options);
- $this->data->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $this->data->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
- }
- public function Disconnect(){
- $this->data = NULL;
- $this->isConn = FALSE;
- }
- public function getRow($params = []){
- $stmt = $this->data->prepare("SELECT * FROM users WHERE id = ?");
- $stmt->execute($params);
- return $stmt->fetch();
- }
- }
- $user = new Database();
- ?>
Add Comment
Please, Sign In to add comment