-
Notifications
You must be signed in to change notification settings - Fork 1
/
lib_Chalesh.php
100 lines (84 loc) · 2.46 KB
/
lib_Chalesh.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<?php
//CREATE TABLE `alirezaz_Robots`.`chalesh` ( `id` INT NOT NULL AUTO_INCREMENT , `QU` VARCHAR(5000) NOT NULL , PRIMARY KEY (`id`)) ENGINE = InnoDB;
// define('SERVER_NAME','localhost:3306');
// define("USER_NAME","alirezaz");
// define("USER_PASSWORD","Ab_4317247");
// define("DB_NM","alirezaz_Robots");
// define("ROBOTS","CHALESH");
class lib_Chalesh{
private $SERVER_NAME;
private $USER_NAME;
private $USER_PASSWORD;
private $DB_NM;
public function __Construct($SERVER_NAME,$USER_NAME,$USER_PASSWORD,$DB_NM){
$this->SERVER_NAME = $SERVER_NAME;
$this->USER_NAME = $USER_NAME;
$this->USER_PASSWORD = $USER_PASSWORD;
$this->DB_NM = $DB_NM;
}
private function cov(){
$SERVER_NAME = $this->SERVER_NAME;
$USER_NAME = $this->USER_NAME;
$USER_PASSWORD = $this->USER_PASSWORD;
$DB_NM = $this->DB_NM;
$all = array(
'S'=>$SERVER_NAME,
'UN'=>$USER_NAME,
'UP'=>$USER_PASSWORD,
'D'=>$DB_NM
);
return $all;
}
private function connect(){
$all = $this->cov();
$link = mysqli_connect($all['S'],$all['UN'],$all['UP'],$all['D']);
if (mysqli_connect_errno($link)){
return "Failed to connect to MySQL: " . mysqli_connect_error($link);
}
return $link;
}
private function query($qr){
$link = $this->connect();
if(empty($qr)){
return "qurery is empty";
}
$result = mysqli_query($link,$qr);
mysqli_close($link);
return $result;
}
// INSERT INTO `CHALESH` (`id`, `username`, `password`, `Date`) VALUES (NULL, 'username', 'password', 'Date ')
public function insert($QU){
$qr = "INSERT INTO `".CHALESH."` (`id`, `QU`) VALUES (NULL, '$QU');";
$result = $this->query($qr);
return $result;
}
public function select($id){
$qr = "SELECT `QU` FROM `".CHALESH."` WHERE id = '$id'";
$result = $this->query($qr);
$row = mysqli_fetch_array($result);
return $row;
}
public function delete($id){
$qr = "DELETE FROM `".CHALESH."` WHERE id = '$id'";
$result = $this->query($qr);
$row = mysqli_fetch_array($result);
return $row;
}
// INSERT INTO `CHALESH` (`id`, `username`, `password`, `Date`) VALUES (NULL, 'username', 'password', 'Date ')
public function update($id,$QU){
$qr = "UPDATE `".CHALESH."` SET `QU`='$QU' WHERE `id`='$id'";
$result = $this->query($qr);
$row = mysqli_fetch_array($result);
return $row;
}
public function updatepassword_username($username){
$qr = "UPDATE `".CHALESH."` SET `password` = '$password' WHERE `username`='$username'";
$result = $this->query($qr);
return $result;
}
public function count(){
$qr = "select * from ".CHALESH;
$result = $this->query($qr);
return mysqli_num_rows($result);
}
}