Jump to content

error in exexute sql from my script


Recommended Posts

Hi all,

 

I am trying to write owm php script from importing data from xml file.

 

I have function


function updateCategory ($name, $level_depth, $lang)
{
    echo 'UPDATE Kategorie '.$name."<br />";
    $sql = 'UPDATE '._DB_PREFIX_.'category c, '._DB_PREFIX_.'category_lang cl SET date_upd = now() WHERE c.id_category = cl.id_category AND cl.name = "'.$name.'" AND cl.id_lang = '.$lang.' AND c.level_depth = '.$level_depth.';';
    $flag = Db::getInstance()->execute($sql);
    if ( !$flag ) echo "Chyba pri Update category: ".$name."<br />";
}

execute sql produce error, when I am using the sql command from phpmyadmin is ok, but in script produce error even when i see in database the date_upd is changed to now

Link to comment
Share on other sites

maybe is thata problem?

Fatal error: Uncaught Cannot execute queries while other unbuffered queries are activUne. Consider using PDOStatement::fetchAll(). Alternatively, if your code is only ever going to run against mysql, you may enable query buffering by setting the PDO::MYSQL_ATTR_USE_BUFFERED_QUERY attribute.<br /><br /><pre>UPDATE ps_category c, ps_category_lang cl SET date_upd = now() WHERE c.id_category = cl.id_category AND cl.name = "Elektronická cigareta" AND cl.id_lang = 1 AND c.level_depth = 2;</pre> thrown in D:\web\ps16\classes\db\Db.php on line 635
Link to comment
Share on other sites

It seems I find the problem

 

before I have this SQL

    $sql = 'SELECT c.id_category FROM '._DB_PREFIX_.'category_lang cl, '._DB_PREFIX_.'category c WHERE c.id_category = cl.id_category AND cl.name="'.$name.'" AND c.level_depth='.($level_depth).' AND cl.id_lang = '.$lang.';';
    $res = mysql_query($sql);
    if (mysql_num_rows($res)>0)
    {
        echo 'Kategorie '.$name.' jiz existuje'."<br />";
        return true;
    } else
    {
        echo 'Kategorie '.$name.' neni v systemu'."<br />";
        return false;
    }

when I changeid to

 $sql = 'SELECT c.id_category FROM '._DB_PREFIX_.'category_lang cl, '._DB_PREFIX_.'category c WHERE c.id_category = cl.id_category AND cl.name="'.$name.'" AND c.level_depth='.($level_depth).' AND cl.id_lang = '.$lang.';'
    Db::getInstance()->ExecuteS($sql);
    $num_rows = Db::getInstance()->NumRows();
    if ($num_rows>0)
    {
        echo 'Kategorie '.$name.' jiz existuje'."<br />";
        return true;
    } else
    {
        echo 'Kategorie '.$name.' neni v systemu'."<br />";
        return false;
    }

now is everything ok

Link to comment
Share on other sites

×
×
  • Create New...