i have a error in joomla - query please. i have and error in this query

拟墨画扇 提交于 2019-12-14 03:36:10

问题


$datos = explode(';',$linea);
    $product_ean = trim($datos[0]);
    $product_price = trim($datos[1]);
    $name_es = trim($datos[2]);
    $short_description_es = trim($datos[3]);

    echo $product_ean,'<br>';
    echo $product_price,'<br>';
    echo $name_es ,'<br>';
    echo $short_description_es,'<br>';

    $db = JFactory::getDbo();
    $query = $db->getQuery(true);

    $columns = array('product_id' ,'product_ean', 'product_price', 'name_es-ES', 'short_description_es-ES');
    $values = array(NULL, $product_ean, $product_price, $name_es, $short_description_es);

    $query
        ->insert($db->quoteName('vrg_jshopping_products'))
        ->columns($db->quoteName($columns))
        ->values(implode(',', $values));

    $db->setQuery($query);
    $db->execute();

Error displaying the error page: Application Instantiation Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '600,1000,articulo nuevo 1,Articulo de test 1)' at line 3

SQL=INSERT INTO vrg_jshopping_products (product_id,product_ean,product_price,name_es-ES,short_description_es-ES) VALUES (,600,1000,articulo nuevo 1,Articulo de test 1)


回答1:


You are getting sql error because you have not quoted your values.You can use below code.

$columns = array('product_id' ,'product_ean', 'product_price', 'name_es-ES', 'short_description_es-ES');
$values = array(NULL, $product_ean, $product_price, $name_es, $short_description_es);


// Prepare the insert query.
$query
   ->insert($db->quoteName($table))
   ->columns($db->quoteName($columns))
   ->values(implode(',', $db->quote($values)));


来源:https://stackoverflow.com/questions/31883422/i-have-a-error-in-joomla-query-please-i-have-and-error-in-this-query

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!