44
55use  App \Core \Library \EnvReader ;
66use  PDO ;
7+ use  PDOException ;
78
89class  Database
910{
10-  private  $ servername
11-  private  $ username
12-  private  $ database
13-  private  $ password
14-  private  $ charset
15-  protected  static  $ conn
11+  private  string $ servername
12+  private  string $ username
13+  private  string $ database
14+  private  string $ password
15+  private  string $ charset
16+  protected  static  mixed $ conn
1617
1718 public  function  __construct ()
1819 {
@@ -29,31 +30,32 @@ public function __destruct() {
2930 $ this disconnect ();
3031 }
3132
32-  private  function  connect (){
33+  private  function  connect (): void 
34+  {
3335 try  {
3436 self ::$ connnew  PDO ("mysql:host= " .$ this servername .";dbname= " .$ this database , $ this username , $ this password );
3537 self ::$ connsetAttribute (PDO ::ATTR_ERRMODE , PDO ::ERRMODE_EXCEPTION );
3638 self ::$ connexec ("set names  " .$ this charset );
3739 } catch (PDOException $ e
3840 echo  "Connection failed:  "  . $ egetMessage ();
3941 }
40-  return  self ::$ conn
4142 }
4243
43-  public  function  disconnect () {
44+  public  function  disconnect (): void 
45+  {
4446 self ::$ connnull ;
4547 }
4648
47-  protected  function  getById ($ table$ columns"* " , $ wherenull ){
49+  protected  static function  getById ($ table$ columns"* " , $ wherenull ){
4850 $ whereis_null ($ where"WHERE  $ where  : null ;
49-  $ sql"SELECT  $ columns FROM  $ table$ where"  ;
50-  $ que$ this -> conn ->prepare ($ sql
51+  $ sql"SELECT  "   .  $ columns.  " FROM  "  .  $ table.  " "  .  $ where
52+  $ queself :: $ connprepare ($ sql
5153 $ queexecute ();
5254 return  $ quefetchAll ();
5355 }
5456
55-  public  static  function  getAll ($ table$ columns"* " , ){
56-  $ sql"SELECT  $ columns FROM  $ table"  ;
57+  public  static  function  getAll ($ table$ columns"* " ){
58+  $ sql"SELECT  "   .  $ columns.  " FROM  "  .  $ table
5759 $ queself ::$ connprepare ($ sql
5860 $ queexecute ();
5961 return  $ quefetchAll ();
0 commit comments