我在joomla中有错误 - 请查询。我有和这个查询中的错误(i have a error in joomla - query please. i have and error in this query)

158 IT屋
$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)

解决方案

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

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

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





显示错误页面时出错:Application Instantiation
错误:您的SQL语法中有错误;检查与MySQL服务器版本对应的手册,以便在第3行600,1000,articulo nuevo 1,Articulo de test 1)附近使用正确的语法



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


解决方案

您收到sql错误,因为您没有引用过您可以使用以下代码。



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


//准备插入查询。
$查询
- > insert($ db-> quoteName($ table))
- > columns($ db-> quoteName($ columns))
- > values(implode(',',$ db-> quote($ values)));

本文地址:IT屋 » 我在joomla中有错误 - 请查询。我有和这个查询中的错误