Piwik_Query in plugin?

I don’t understand what’s happening… Some documentation could be useful. I am trying to run some queries in a plugin. The following:


$query = ....;
Piwik_Exec($query);

works in the install() function and the tables specified in the query are created. Then, I try again:


$query = ....;
Piwik_Exec($query);

in a function which is called from a hook. Nothing happens, and in Apache error log I get this:

[Fri Jul 05 11:51:59 2013] [error] [client 10.0.0.115] PHP Fatal error: Class ‘Zend_Registry’ not found in /home/pavelk/www/piwik/core/PluginsFunctions/Sql.php on line 46

However, if I do:


Piwik_Query(...);

it works… What is the difference, which one should I use and why do I get the error for Piwik_Exec($query) in one function but not another?

you should use Piwik_Query for SELECT/UPDATE/INSERT etc