Author Topic: insert new query  (Read 2176 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: 10040
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 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.
I should 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: 10040
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 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.
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/