Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit c7a4be2

Browse files
author
kamrankarimov
committed
add return types, propert types and fix errors
1 parent 0cce7ce commit c7a4be2

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

‎app/core/database/Database.php‎

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,16 @@
44

55
use App\Core\Library\EnvReader;
66
use PDO;
7+
use PDOException;
78

89
class 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::$conn = new PDO("mysql:host=".$this->servername.";dbname=".$this->database, $this->username, $this->password);
3537
self::$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
3638
self::$conn->exec("set names ".$this->charset);
3739
} catch(PDOException $e) {
3840
echo "Connection failed: " . $e->getMessage();
3941
}
40-
return self::$conn;
4142
}
4243

43-
public function disconnect() {
44+
public function disconnect(): void
45+
{
4446
self::$conn = null;
4547
}
4648

47-
protected function getById($table, $columns = "*", $where=null){
49+
protected staticfunction getById($table, $columns = "*", $where=null){
4850
$where = !is_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+
$que = self::$conn->prepare($sql);
5153
$que->execute();
5254
return $que->fetchAll();
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
$que = self::$conn->prepare($sql);
5860
$que->execute();
5961
return $que->fetchAll();

‎composer.json‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@
55
"App\\Models\\" : "app/Models",
66
"App\\Controllers\\" : "app/Controllers"
77
}
8+
},
9+
"require": {
10+
"ext-pdo": "*"
811
}
912
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /