When a new subscription is added or an existing subscription is changed in aMember I need update th exp_members_subscriptions table in ExpressionEngine. I have looked through the aMember code but it isn't obvious where I should make changes, can anyone provide guidence please?
You can use hooks/events Am_Event::SUBSCRIPTION_ADDED, Am_Event::SUBSCRIPTION_DELETED. Here you can find info how to use events: http://www.amember.com/docs/API/HookManager You can put your custom code to special file for customizations - site.php http://www.amember.com/docs/Site.php_file
If I understand correctly; I add functions and hooks for each subscription event inside site.php. But how I access the expressionengine database to update the table from this file?
Yes, you are right regarding events. To update database you can use any standard PHP approach. It is either mysqli (http://php.net/mysqli) or PDO (http://php.net/pdo). Another approach is use aMember function (which utilize PDO behind the scene). Please have to look http://www.amember.com/docs/API/Db (Please note aMember database user should has access to your Expressionengine database). I hope it will be useful for you.
I would prefer to use the aMember API, but the documenation seems to assume you want to access the am database, how do I tell the API that I want to use the expressionengine database?
In case aMember database user (amember/application/configs/config.php) has access to your Expressionengine database than you can use this code: PHP: Am_Di::getInstance()->db->query("INSERT INTO exp_members_subscriptions ....."); Otherwise you need to grant necessary access to amember database user.
You are right. It is my mistake. This code will work only if you have all tables (aMember and Expressionengine in same database). In case you have tables for Expressionengine in separate database you can use: PHP: $db = Am_Db::connect(array( 'user' => 'Username', 'pass' => 'Password', 'host' => 'Host', 'db' => 'Database Name', 'port' => 'Port'));$db->query("INSERT INTO exp_members_subscriptions .....");
I have a new hook working successfully for Am_Event::SUBSCRIPTION_ADDED, but I cannot get hooks for SUBSCRIPTION_REMOVED SUBSCRIPTION_UPDATED to work. I have tried changing these to : Am_Event::USER_AFTER_DELETE Am_Event::USER_AFTER_UPDATE as the documentation suggests http://www.amember.com/docs/API/HookManager (the first 2 are deprecated), but still no luck.