问题
$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