Advertisement
Guest User

Untitled

a guest
Oct 5th, 2018
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.84 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Created by PhpStorm.
  4.  * User: MrSkoper
  5.  * Date: 04.10.2018
  6.  * Time: 18:35
  7.  */
  8.  
  9. namespace BOT\DataBase;
  10.  
  11. class ClientAuth extends \PDO
  12. {
  13.  
  14.     private $DB;
  15.     private $Prepare = null;
  16.     private $Result = null;
  17.  
  18.     public function __construct(?int $TypeDataBase = 0, ?string $Host = '127.0.0.1', ?int $Port = 3306, ?string $User = 'root', ?string $UserPassword = null, ?string $DataBase = null, ?array $Options = null)
  19.     {
  20.         try{
  21.             switch($TypeDataBase){
  22.                 default: $dsn = 'sqlite:'.((!empty($Host)) ? $Host : ':memory:'); break;
  23.                 case 1: $dsn = 'mysql:host='.$Host.';port='.$Port.';dbname='.$DataBase; break;
  24.             }
  25.             new \PDO($dsn, $User, $UserPassword, $Options);
  26.  
  27.             self::CreateTable($this);
  28.         }catch (\Exception $e){
  29.             print_r($e->getMessage()."\n");
  30.         }
  31.     }
  32.  
  33.     protected function CreateTable($DB, ?string $TableName = 'Auth', ?array $TableTitle = ['TitleType' => 'TitleName']){
  34.         if(!$this->exec('SELECT * FROM `TEST`')){
  35.             $Title = null;
  36.  
  37.             foreach($TableTitle as $TitleType => $TitleName){
  38.                 end($TableTitle);
  39.                 $Title .= ($TitleType !== key($TableTitle) && $TableName !== current($TableTitle)) ?
  40.                     $TableName.' '.$TitleType.','.' ': $TableName.' '.$TitleType;
  41.             }
  42.  
  43.             $this->Prepare[] .= $this->prepare(
  44.                 'CREATE TABLE'.' '.$TableName.' '.'('.$Title.')'.';'
  45.             );
  46.  
  47.             self::PrepareExecute();
  48.         }else{
  49.             throw new \PDOException('Table is created');
  50.         }
  51.     }
  52.  
  53.     public function PrepareExecute(){
  54.  
  55.         try {
  56.  
  57.             print_r($this->Prepare);
  58.  
  59.             return false;
  60.         }catch (\PDOException $e) {
  61.             print_r($e);
  62.         }
  63.     }
  64.  
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement