News:

Looking for documentation? Take a look on our wiki

Main Menu

insert new query

Started by alin, January 15, 2015, 12:35:11 PM

Previous topic - Next topic

alin

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?

alin

Ok, I found the problem  :P

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

Milbo

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.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/

alin

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.

Milbo

But the db maybe changed. If there is a function doing it for you, you should use the function and not do it manually.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/