Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Database {
- public $isConn;
- protected $datab;
- // Connect zur DB
- public function __construct($username = "root_portal", $password = "Mxt59l$4", $host = "localhost", $dbname = "db12354864"){
- $this->isConn = TRUE;
- try{
- $this->datab = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8", $username, $password);
- $this->datab->setAttribute(PDO::ATRR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $this->datab->setAttribute(PDO::ATRR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
- }catch(PDOException $e){
- throw new Exception($e->getMessage());
- }
- }
- // Verbindung beenden
- public function Disconnect(){
- $this->datab = NULL;
- $this->isConn = FALSE;
- }
- // Hole eine Spalte
- public function getRow($query, $params = array()){
- try {
- $stmt = $this->datab->prepare($query);
- $stmt->execute($params);
- return $stmt->fetch();
- }catch (PDOException $e){
- throw new Exception($e->getMessage());
- }
- }
- }
- test php
- <?php
- require_once 'module/mysqli.php';
- $db = new Database();
- $getRow = $db->getRow("SELECT * FROM user WHERE id = ?", $params = array(1));
- var_dump($getRow);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement