-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpraise.php
54 lines (53 loc) · 1.24 KB
/
praise.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
<?php
class Conmysql{
public $servername;
public $username;
public $password;
public $dbname;
public $con = '';
public function __construct($servername,$username,$password,$dbname){
$this->servername = $servername;
$this->username = $username;
$this->password = $password;
$this->dbname = $dbname;
}
public function getConnection(){
try {
$dsn = "mysql:host=$this->servername;dbname=$this->dbname;";
$this->con = new PDO($dsn,$this->username,$this->password);
}
catch(PDOException $e)
{
echo $e->getMessage();
}
}
public function updateData($sql){
if($this->con == null){
$this->getConnection();
}
header('content-type:application/json;charset=utf8');
$res = $this->con->exec($sql);
$arr = array('result'=>$res);
echo json_encode($arr);
$this->closeCon();
}
public function closeCon(){
$this->con = null;
}
}
/**
*
*/
class realCon extends Conmysql
{
public function __construct($servername,$username,$password,$dbname){
parent::__construct($servername,$username,$password,$dbname);
}
public function updateRealData(){
$sql = "UPDATE user SET num = num+1 WHERE id = 1";
$this->updateData($sql);
}
}
$praiseConn = new realCon('localhost','root','123456','my');
$praiseConn->updateRealData();
?>