-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathread_doc.php
More file actions
76 lines (70 loc) · 2.17 KB
/
read_doc.php
File metadata and controls
76 lines (70 loc) · 2.17 KB
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
<?php
$dir = "C:/Users/Samark/Desktop/DocLaravel/";
$file = scandir($dir);
foreach ($file as $key => $value) {
if(!in_array($value, array(".","..")) && !is_dir($dir.$value)) {
$readtext = file_get_contents($dir.$value);
$data = array(
'title' => $value,
'detail' => mysql_real_escape_string($readtext),
);
$check_exists = check_exists($value);
// debug($check_exists,1,1);
if(!empty($check_exists)) {
/* update */
updatebook($check_exists['id'],mysql_real_escape_string($readtext));
}else{
savedata($data);
}
}
}
function savedata($data= array()){
mysql_connect('localhost','root','') or die(mysql_error());
mysql_select_db('readbook') or die(mysql_error());
mysql_query("SET NAMES UTF8");
$title = $data['title'];
$detail = $data['detail'];
// $query = "insert into book value(0,{$title},{$detail},now())";
$sql = "INSERT INTO `readbook`.`book` (`id`, `title`, `detail`, `create_date`) VALUES (NULL, '{$title}', '{$detail}', CURRENT_TIMESTAMP);";
$excute = mysql_query($sql) or die(mysql_error());
echo "Title: ".$title."\r\n";
}
function check_exists($value='')
{
mysql_connect('localhost','root','') or die(mysql_error());
mysql_select_db('readbook') or die(mysql_error());
mysql_query("SET NAMES UTF8");
$sql ="select * from book where title ='{$value}'";
echo "\r\n";
echo $sql;
$excute = mysql_query($sql) or die(mysql_error());
if($excute) {
if(mysql_num_rows($excute) <>0) {
return mysql_fetch_assoc($excute);
}else{
return false;
}
}else{
exit('fail');
}
}
function updatebook($id=0,$detail="")
{
mysql_connect('localhost','root','') or die(mysql_error());
mysql_select_db('readbook') or die(mysql_error());
mysql_query("SET NAMES UTF8");
$sql = "update book set detail ='{$detail}' where id={$id} ";
// exit($sql);
$excute = mysql_query($sql) or die(mysql_error());
if ($excute) {
return true;
}else{
return false;
}
}
function debug($value,$v=false,$e=false)
{
echo "<pre>"; print_r($value); echo "</pre>";
if($v == true) var_dump($value);
if($e == true) exit('bugs');
}