мой код и я принимаю ошибку. Интересно, как я решаю проблемы
<?php
include_once 'simple_html_dom.php';
try {
$dsn = "mysql:host=localhost;db=test";
$username ="root";
$password = "";
$options = array(PDO::MYSQL_ATTR_INIT_COMMAND=> 'SET NAMES UTF8' ,
PDO::ATTR_ERRMODE=>PDO::ERRMODE_EXCEPTION );
$conn = new PDO($dsn, $username, $password, $options);
} catch (Exception $ex) {
echo "Hata kodu " . $ex->getMessage();
}// markaları alalım
$markaurl ="https://www.xxxx/chip-tuning";
$markaurlhtml = file_get_html($markaurl);foreach ($markaurlhtml->find('div[class="darkGrid mediumBordered"] ul[id="brandsList"] a') as $markalar0) {
/* //Buna hiç gerek yokmuş üstteki kod gayet güzel ve esnek oldu :D
foreach ($markalar0->find('ul[id="brandsList"] a') as $markalar0) {
echo $markalar->href . "<br>";
} */
// echo $markalar0->href . "<br>";
// $mrk = $markalar0->href;
try {
$deyim = $conn->prepare("INSERT INTO remap_marka (marka) VALUES (?)");
$deyim->bindParam(1, $mrk);
$deyim->execute();
} catch (Exception $ex) {
echo $ex->getMessage() . "<br>";
}}?>
Это решение, которое вам нужно для вашего кода. Пожалуйста, замените это:
<?php
include_once ("simple_html_dom.php");
try {
$dsn = "mysql:host=localhost;dbname=test";
$username = "root";
$password = "";
$options = array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES UTF8',
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
);
$conn = new PDO($dsn, $username, $password, $options);
} catch (PDOException $ex) {
echo "Hata kodu " . $ex->getMessage();
}
// markaları alalım
$markaurl ="https://www.xxxx/chip-tuning";
$markaurlhtml = file_get_html($markaurl);
foreach ($markaurlhtml->find('div[class="darkGrid mediumBordered"] ul[id="brandsList"] a') as $markalar0) {
/*
// Buna hiç gerek yokmuş üstteki kod gayet güzel ve esnek oldu :D
foreach ($markalar0->find('ul[id="brandsList"] a') as $markalar0) {
echo $markalar->href . "<br>";
}
// echo $markalar0->href . "<br>";
// $mrk = $markalar0->href;
*/
try {
$deyim = $conn->prepare("INSERT INTO remap_marka (marka) VALUES (?)");
$deyim->bindParam(1, $mrk);
$deyim->execute();
} catch (Exception $ex) {
echo $ex->getMessage() . "<br>";
}
}
?>
Я надеюсь, что это полезно, привет 🙂
Других решений пока нет …