-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjsfrmwkdb.php
64 lines (55 loc) · 2.23 KB
/
jsfrmwkdb.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
<?php
$conn = new mysqli('127.0.0.1','','','');
if($conn->connect_error){
die("Connection failed: ".$conn->connect_error);
}
switch($_POST['action']){
case "refresh":
refresh();
break;
case "datain":
datain();
break;
default:
echo "Error";
break;
}
function refresh(){
global $conn;
$stmt = $conn->prepare('SELECT `vue`,`react`,`angular`, DATE_FORMAT(`date`, "%m/%e") d, `date` x FROM `web` ORDER BY x ASC
');
if (!$stmt->execute()) {
echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
}
$arr = $stmt->get_result()->fetch_all(MYSQLI_ASSOC);
$stmt->close();
$conn->close();
echo json_encode($arr);
}
function datain(){
$content = htmlspecialchars(file_get_contents("https://www.104.com.tw/jobs/search/?keyword=vue"));
preg_match('/-(.*?)個工作機會/', $content, $vue);
$content = htmlspecialchars(file_get_contents("https://www.104.com.tw/jobs/search/?keyword=react"));
preg_match('/-(.*?)個工作機會/', $content, $react);
$content = htmlspecialchars(file_get_contents("https://www.104.com.tw/jobs/search/?keyword=angular"));
preg_match('/-(.*?)個工作機會/', $content, $angular);
global $conn;
$stmt = $conn->prepare('INSERT INTO `web`
(`vue`,
`react`,
`angular`)
SELECT ?,?,?
FROM DUAL
WHERE NOT EXISTS (SELECT *
FROM `web`
WHERE CURDATE() =
Date_format(`date`, "%Y/%m/%e")) ');
$stmt->bind_param("iii", $vue[1], $react[1], $angular[1]);
if (!$stmt->execute()) {
$err = "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
}
$stmt->close();
$conn->close();
echo json_encode(mysqli_affected_rows($conn));
}
?>