S
S
Sanya8992019-10-03 13:46:02
PHP
Sanya899, 2019-10-03 13:46:02

Parser php oracle not writing to db?

Gives an error message:

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, ','));

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kerm, 2019-10-03
@Sanya899

Try like this:

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);

I
idShura, 2019-10-03
@idShura

Oracle does not support this insert format:
I can't answer in more detail right now... google about INSERT ALL

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question