Author Topic: insert new query  (Read 3898 times)

alin

  • Beginner
  • *
  • Posts: 20
  • VirtueMart Version: 3
insert new query
« 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?

alin

  • Beginner
  • *
  • Posts: 20
  • VirtueMart Version: 3
Re: insert new query
« Reply #1 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();

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 10663
  • VM4.0.232 Eagle Owl
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 4 on joomla 3
Re: insert new query
« Reply #2 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.
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

  • Beginner
  • *
  • Posts: 20
  • VirtueMart Version: 3
Re: insert new query
« Reply #3 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.

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 10663
  • VM4.0.232 Eagle Owl
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 4 on joomla 3
Re: insert new query
« Reply #4 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.
Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/