con
This commit is contained in:
		
							parent
							
								
									231710e996
								
							
						
					
					
						commit
						81855c900e
					
				
							
								
								
									
										28
									
								
								index.php
								
								
								
								
							
							
						
						
									
										28
									
								
								index.php
								
								
								
								
							|  | @ -8,25 +8,35 @@ interface ISqlBase { | |||
|     //public function Update(): string;
 | ||||
|     //public function Delete(): string;
 | ||||
| } | ||||
| 
 | ||||
| class ConnectionManager { | ||||
|     private static $connection; | ||||
|     public static function connect(string $connectionString) { | ||||
|         self::$connection = new PDO($connectionString); | ||||
|     } | ||||
|     public static function Query(string $query, $params, $output = 'stdObject') { | ||||
|         $stmt = self::$connection->prepare($query); | ||||
|         $stmt->execute($params); | ||||
|         return $stmt->fetchObject($output); | ||||
|     } | ||||
| } | ||||
| abstract class BaseModel { | ||||
|     protected $sql; | ||||
|     protected static $sql; | ||||
|      | ||||
|     public function __construct(ISqlBase $sql) { | ||||
|         $this->sql = $sql; | ||||
|         self::$sql = $sql; | ||||
|     } | ||||
|      | ||||
|     public static function Get(int $id) { | ||||
|         return get_called_class(); | ||||
|          $stmt = $pdo->prepare('SELECT id, name FROM users WHERE id=?'); | ||||
|          $stmt->execute([$id]); | ||||
|          return $stmt->fetchObject(__CLASS__); | ||||
|         return ConnectionManager::Query( | ||||
|             self::$sql->Get(), | ||||
|             [], | ||||
|             get_called_class()); | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| class JobSql implements ISqlBase { | ||||
|     public function Get(): string { | ||||
|         return ""; | ||||
|         return "Select * from jobs where id = :id"; | ||||
|     } | ||||
|      | ||||
| } | ||||
|  | @ -36,6 +46,8 @@ class Job extends BaseModel { | |||
|         parent::__construct( new JobSql() ); | ||||
|     } | ||||
| } | ||||
| $dns = 'pgsql:host=localhost;port=5432;dbname=dynamic_dev;user=test;password=pas123'; | ||||
| ConnectionManager::Connect($dns); | ||||
| echo " | ||||
| 
 | ||||
| ";
 | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue