-
Notifications
You must be signed in to change notification settings - Fork 0
/
importData.php
54 lines (41 loc) · 1.13 KB
/
importData.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
$path = dirname(__FILE__);
include($path.'\db_sqlite.php');
$arr = readTxtFile('../joke_image.txt');
$db = new db_sqlite();
$conn = $db->connect_sqlite();
for ($i=0; $i < count($arr); $i++) {
$item = json_decode($arr[$i]);
$picUrl = $item->picUrl;
$mediaId = $item->mediaId;
//echo $item->mediaId.'<br>';
$sql = "insert into image(mediaid,picurl) values('".$mediaId."','".$picUrl."')";
echo $sql.'<br>';
$result = $db->exec_sqlite($conn,$sql);
echo $result.'<br>';
}
$aa = $db->commit_sqlite($conn);
echo $aa.'<br>';
/*$item = json_decode($arr[0]);
$picUrl = $item->picUrl;
$mediaId = $item->mediaId;
$sql = "insert into image(mediaid,picurl) values('".$mediaId."','".$picUrl."')";
echo $sql.'<br>';*/
//$result = $db->exec_sqlite($conn,$sql);
$db->close_sqlite($conn);
function readTxtFile($file){
$arr=array();
$list = array();
$fp=fopen($file,'r');
while ($arr[] = fgets($fp)) {
}
fclose($fp);
foreach ($arr as $key => $value) {
if(strlen($value) >2){
$list[] = $value;
}
//echo $key.'=>'.$value.',count:'.strlen($value).'<br>';
}
return $list;
}
?>