Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Created by PhpStorm.
- * User: MrSkoper
- * Date: 04.10.2018
- * Time: 18:35
- */
- namespace BOT\DataBase;
- class ClientAuth extends \PDO
- {
- private $DB;
- private $Prepare = null;
- private $Result = null;
- 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)
- {
- try{
- switch($TypeDataBase){
- default: $dsn = 'sqlite:'.((!empty($Host)) ? $Host : ':memory:'); break;
- case 1: $dsn = 'mysql:host='.$Host.';port='.$Port.';dbname='.$DataBase; break;
- }
- new \PDO($dsn, $User, $UserPassword, $Options);
- self::CreateTable($this);
- }catch (\Exception $e){
- print_r($e->getMessage()."\n");
- }
- }
- protected function CreateTable($DB, ?string $TableName = 'Auth', ?array $TableTitle = ['TitleType' => 'TitleName']){
- if(!$this->exec('SELECT * FROM `TEST`')){
- $Title = null;
- foreach($TableTitle as $TitleType => $TitleName){
- end($TableTitle);
- $Title .= ($TitleType !== key($TableTitle) && $TableName !== current($TableTitle)) ?
- $TableName.' '.$TitleType.','.' ': $TableName.' '.$TitleType;
- }
- $this->Prepare[] .= $this->prepare(
- 'CREATE TABLE'.' '.$TableName.' '.'('.$Title.')'.';'
- );
- self::PrepareExecute();
- }else{
- throw new \PDOException('Table is created');
- }
- }
- public function PrepareExecute(){
- try {
- print_r($this->Prepare);
- return false;
- }catch (\PDOException $e) {
- print_r($e);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement