Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //MYSQLI Datei
- class Database {
- public $isConn;
- protected $datab;
- // Connect zur DB
- public function __construct($username = "root", $password = "password", $host = "localhost", $dbname = "dbname", $options = array()){
- $this->isConn = TRUE;
- try{
- $this->datab = new PDO("mysql:host={$host};dbname={$dbname};charset=utf8", $username, $password, $options);
- $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 = ?", array(1));
- print_r($getRow);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement