Добавлен цикл проверки сайтов
This commit is contained in:
@ -20,7 +20,7 @@ class ContingentParser
|
||||
"numberBMF" => "th",
|
||||
"numberP" => "th",
|
||||
"numberPF" => "th",
|
||||
"numberAll" => "th"
|
||||
"numberAll" => ["th", "td"]
|
||||
];
|
||||
|
||||
public function __construct(string $html, string $template)
|
||||
@ -36,7 +36,14 @@ class ContingentParser
|
||||
{
|
||||
$data = array();
|
||||
foreach (self::FIELDS as $field => $tag) {
|
||||
$data[$field] = $this->xpath->query($this->template . $tag . "[@itemprop=\"$field\"]");
|
||||
if (!is_array($tag)) {
|
||||
$data[$field] = $this->xpath->query($this->template . $tag . "[@itemprop=\"$field\"]");
|
||||
} else {
|
||||
$x = $this->xpath->query($this->template . $tag[0] . "[@itemprop=\"$field\"]");
|
||||
$y = $this->xpath->query($this->template . $tag[1] . "[@itemprop=\"$field\"]");
|
||||
$data[$field] = $x > $y ? $x : $y;
|
||||
}
|
||||
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
@ -46,7 +53,7 @@ class ContingentParser
|
||||
$data = $this->parse();
|
||||
$records = array();
|
||||
|
||||
for ($i = 0; $i < $data['numberAll']->length; $i++) {
|
||||
for ($i = 0; $i < $data['eduCode']->length; $i++) {
|
||||
$contingentRow = new ContingentRow(
|
||||
$data['eduCode']->item($i)->textContent,
|
||||
$data['eduName']->item($i)->textContent,
|
||||
|
@ -1,9 +1,8 @@
|
||||
<?php
|
||||
namespace App\Library;
|
||||
|
||||
use PDO;
|
||||
use PDOException;
|
||||
|
||||
use PDO;
|
||||
class Database extends PDO
|
||||
{
|
||||
public function __construct(string $dsn, string $username, string $password)
|
||||
@ -27,69 +26,17 @@ class Database extends PDO
|
||||
echo "Подключение прервано!\n";
|
||||
}
|
||||
|
||||
public function insert(string $table, array $data) : void
|
||||
public function executeQuery(string $sql, array $params) : array|bool
|
||||
{
|
||||
$keys = array_keys($data);
|
||||
$sql = "INSERT INTO $table (";
|
||||
foreach ($keys as $key) {
|
||||
$sql .= "$key,";
|
||||
}
|
||||
$sql = substr_replace($sql, ")", -1);
|
||||
$sql .= " VALUES (";
|
||||
foreach ($keys as $key) {
|
||||
$sql .= ":$key,";
|
||||
}
|
||||
$sql = substr_replace($sql,"", -1);
|
||||
$stmt = $this->prepare($sql);
|
||||
|
||||
foreach ($data as $key => $row) {
|
||||
try {
|
||||
$stmt->bindParam(":$key", $row[$key]);
|
||||
$stmt->execute();
|
||||
} catch (PDOException $e) {
|
||||
echo "Ошибка запроса: " . $e->getMessage() . "\n";
|
||||
try {
|
||||
$stmt = $this->prepare($sql);
|
||||
for ($i = 0; $i < count($params); $i++) {
|
||||
$stmt->bindParam(":v".$i+1, $params[$i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function select(string $table) : array|null
|
||||
{
|
||||
$stmt = $this->prepare("SELECT * FROM $table");
|
||||
try {
|
||||
$stmt->execute();
|
||||
$array = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
} catch (PDOException $e) {
|
||||
echo "Ошибка запроса: " . $e->getMessage() . "\n";
|
||||
} finally {
|
||||
return $array;
|
||||
}
|
||||
}
|
||||
|
||||
public function selectWhere(
|
||||
string $table,
|
||||
array $atributes,
|
||||
array $filters
|
||||
) : array|null {
|
||||
// Строим запрос
|
||||
$sql = "SELECT ";
|
||||
foreach ($atributes as $atribute) {
|
||||
$sql .= "$atribute,";
|
||||
}
|
||||
$sql = substr_replace($sql," ", -1);
|
||||
$sql .= "FROM $table WHERE ";
|
||||
foreach ($filters as $key => $filter) {
|
||||
$sql .= "$key = :$key ";
|
||||
}
|
||||
$stmt = $this->prepare($sql);
|
||||
foreach ($filters as $key => $filter) {
|
||||
$stmt->bindParam(":$key", $filter);
|
||||
}
|
||||
// Выполняем
|
||||
try {
|
||||
$stmt->execute();
|
||||
$array = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
} catch (PDOException $e) {
|
||||
echo "Ошибка запроса: " . $e->getMessage() . "\n";
|
||||
echo "Ошибка запроса: " . $e->getMessage() . "\n";
|
||||
} finally {
|
||||
return $array;
|
||||
}
|
||||
|
Reference in New Issue
Block a user