@Sanya899

Parser php oracle не пишет в БД?

Выдает ошибку:
Warning: oci_execute() expects parameter 1 to be resource, string given in


require_once "simple_html_dom.php";

        error_reporting(E_ALL);
        ini_set('display_errors', '1');
        $conn = oci_connect('ddd', 'ddd', '127.0.0.1/orcl', 'AL32UTF8');


    $brands = array();

    $html = str_get_html(file_get_contents('https://kolesa.kz/cars/'));
    $insert = oci_parse($conn, 'INSERT INTO kolesa_brands (id, name) VALUES');
    $select = $html->find('select[id=auto-car-mm-0]', 0);
    foreach($select->find('option') as $opt)
    {
        if($opt->value == '') continue;
        $insert .= '('.$opt->value.', \''.$opt->plaintext.'\'),';
        $brands[$opt->value] = $opt->plaintext; 
    }
    oci_execute(rtrim($insert, ','));
  • Вопрос задан
  • 162 просмотра
Решения вопроса 1
@Kerm
Попробуй вот так:

require_once "simple_html_dom.php";

error_reporting(E_ALL);
ini_set('display_errors', '1');
$conn = oci_connect('ddd', 'ddd', '127.0.0.1/orcl', 'AL32UTF8');


$brands = array();

$html = str_get_html(file_get_contents('https://kolesa.kz/cars/'));
$i = 'INSERT INTO kolesa_brands (id, name) VALUES';
$select = $html->find('select[id=auto-car-mm-0]', 0);

foreach($select->find('option') as $opt)
{
	if($opt->value == '') continue;
	$i .= ' ('.$opt->value.', \''.$opt->plaintext.'\'),';
	$brands[$opt->value] = $opt->plaintext; 
}

$insert = oci_parse($conn, rtrim($i, ',').';');

oci_execute($insert);
Ответ написан
Пригласить эксперта
Ответы на вопрос 1
idShura
@idShura
Oracle не поддерживает такой формат вставки:

INSERT INTO kolesa_brands (id, name) VALUES (4, 'ARO'), (1, 'Acura'), (2, 'Alfa Romeo')


Я сейчас не могу ответить более подробно... гугли про INSERT ALL
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы