-
Notifications
You must be signed in to change notification settings - Fork 1
/
lib_fact.php
94 lines (79 loc) · 2.73 KB
/
lib_fact.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
<?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","FACT");
class lib_fact{
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 `FACT` (`id`, `username`, `password`, `Date`) VALUES (NULL, 'username', 'password', 'Date ')
public function insert($QU){
$qr = "INSERT INTO `".FACT."` (`id`, `QU`) VALUES (NULL, '$QU');";
$result = $this->query($qr);
return $result;
}
public function select($id){
$qr = "SELECT `QU` FROM `".FACT."` WHERE id = '$id'";
$result = $this->query($qr);
$row = mysqli_fetch_array($result);
return $row;
}
public function delete($id){
$qr = "DELETE FROM `".FACT."` WHERE id = '$id'";
$result = $this->query($qr);
$row = mysqli_fetch_array($result);
return $row;
}
// INSERT INTO `FACT` (`id`, `username`, `password`, `Date`) VALUES (NULL, 'username', 'password', 'Date ')
public function update($id,$QU){
$qr = "UPDATE `".FACT."` SET `QU`='$QU' WHERE `id`='$id'";
$result = $this->query($qr);
$row = mysqli_fetch_array($result);
return $row;
}
public function count(){
$qr = "select * from ".FACT;
$result = $this->query($qr);
return mysqli_num_rows($result);
}
}