VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Coding Central => Topic started by: alin on January 15, 2015, 12:35:11 PM

Title: insert new query
Post by: alin on January 15, 2015, 12:35:11 PM
Hi,

I created a class that does some stuff but I cannot make the SQL query work.

What I did:

$db = JFactory::getDBO();
$q = "UPDATE #__virtuemart_product....";
$db->setQuery($q);

I did test the query and it is correct.

Can anybody help me?
Title: Re: insert new query
Post by: alin on January 15, 2015, 12:47:04 PM
Ok, I found the problem  :P

$db = JFactory::getDBO();
$q = "UPDATE #__virtuemart_product....";
$db->setQuery($q);
$db->query();
Title: Re: insert new query
Post by: Milbo on January 15, 2015, 15:40:58 PM
oh evil, what yah doing.

use

$productM = VmModel::getModel('product');

$productM->store($mDataArray);

Use an array with the data and the system is doing the rest for you.

or use the xref table directly

$data= array('virtuemart_product_id'=>array(1,2,3))

$table = $productM->getTable('product_categories');

$table->bindChecknStore($data);

This is just out of the head, not tested or something, but to give you an idea.
Title: Re: insert new query
Post by: alin on January 15, 2015, 20:42:05 PM
Why so evil? This kind of code is also used somewhere else also.

The query doesn't include user input. The script retrieves information from an external database and updates some information about the product.
Title: Re: insert new query
Post by: Milbo on January 15, 2015, 22:52:38 PM
But the db maybe changed. If there is a function doing it for you, you should use the function and not do it manually.