-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsand_v2.0_pdo.php
More file actions
66 lines (58 loc) · 2.14 KB
/
sand_v2.0_pdo.php
File metadata and controls
66 lines (58 loc) · 2.14 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
<head>
<html lang="ru">
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
</head>
<?php include_once 'header.php';
require_once 'library/simple_html_dom.php';
require_once 'functions.php';
// try {
$dbh = new PDO('mysql:host=localhost;dbname=php_dns', 'gtx', '678352saqejgf2');
// foreach($dbh->query('SELECT * from habra_post') as $row) {
// print_r($row);}
try{
array(PDO::ATTR_PERSISTENT => true);
echo "Подключились УРА!!!\n";
}catch (Exception $e){
die("\nWTF!!! Ошибка подключения! =( ".$e->getMessage());
}
$html = file_get_html('http://habrahabr.ru');
$element='empty';
$date_nextd=date('y-m-d h:i',strtotime('+1 day'));
$date1=date('y-m-d h:i');
foreach($html->find('div.post') as $p => $item){
$title1 = implode(" ", $item->find('h2.post__title'));
$text1 = implode(" ", $item->find('.html_format'));
$url_a = implode(" ", $item->find('a.button'));
$url_b = explode('"', $url_a);
$html_in = file_get_html($url_b[3]);
$full_text = implode(" ", $html_in->find('.html_format'));
try {
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$dbh->beginTransaction();
$dbh->exec("insert into php_dns (title, text_body, reg_date, full_text, next_date, link)
values ($title1,$text1,$date1,$full_text,$date_nextd,$html_in)");
$dbh->commit();
} catch (Exception $e) {
$dbh->rollBack();
echo "\nТа ну епт, опять ошибка =((( " . $e->getMessage();
}
$dbh=null;}
//
//
//
// $result=$dbh->query("INSERT INTO `habra_post`(`title`, `text_body`, `reg_date`, `full_text`, `next_date`, `link`)
// VALUES ($title1,$text1,$date1,$full_text,$date_nextd,$html_in)", $dbh);
// if ($result) {
// echo "<p>Данные успешно добавлены в таблицу.</p>";
// } else {
// // file_put_contents('mylog.txt', mysql_error());
// die('Ошибка в запросе!');
// }}
//
// $dbh = null;
// }
// catch (PDOException $e) {
// print "Error!: " . $e->getMessage() . "<br/>";
// die();
// }
?>