0

I can't find any information about solving this problem. I have a function which make query and loop through table. Its updateBGItems And in loop i'm using updateBGItem which update price and date in mysql.

function updateBGItems($conn)
{
    if ($conn->connect_error)
    {
        die("Błąd połączenia: " . $conn->connect_error);
    }
    $query = 'SELECT `product`,`sku` FROM `bang_itemy`';
    if ($stmt = $conn->prepare($query)) 
    {
        $stmt->execute();
        $stmt->bind_result($product, $sku);
        while ($stmt->fetch()) {
            echo $product . '|' . $sku . '<br/>';
            updateBGItem($conn, $product, $sku);
        }
        $stmt->close();
    }
    $conn->close();
}

This is another function:

function updateBGItem($conn, $productid, $sku)
{
    date_default_timezone_set('Europe/Warsaw');
    $czas = date('H:i:s d.m.Y', time());
    $ceny = checkBGPrice($sku, $productid, 45);

    if ($conn->connect_error)
    {
        die("Błąd połączenia: " . $conn->connect_error);
    }
    $dodaj = $conn->prepare("UPDATE `bang_itemy` SET `priceusd` = ?, `pricepln` = ?, `data` = ? WHERE `product` = ? AND `sku` = ?;");
    $error = $conn->errno . ' ' . $conn->error;
    echo $error; 
    $dodaj->bind_param("sssss", $ceny['cenausd'], $ceny['cenapln'], $czas , $productid, $sku);
    if ($dodaj->execute() === TRUE) 
    {
        $dodaj->close();
        $conn->close();
        return true;
    }
    else
    {
        $dodaj->close();
        $conn->close();
        return false;
    }
}

After a lot of debugging I read this message:

2014 Commands out of sync; you can't run this command now What can I do to run query when i'm fetching another?

Thanks for any help

kaska3er
  • 35
  • 1
  • 5

0 Answers0