Integrating with other Database

Discussion in 'Integration' started by Mogulbasher, Sep 5, 2011.

  1. Mogulbasher

    Mogulbasher New Member

    Joined:
    Aug 29, 2006
    Messages:
    2
    So I am writing a custom plugin to integrate with another database so I can pull the subscription data I have been following the instructions here http://manual.amember.com/Creating_New_Integration_Plugins and I cannot seem to find any guidance on how to write custom SQL queries against the integrated database. I am assuming that we use something like
    Code:
    function recipes_integration_rebuild(&$members){
        global $config, $db, $plugin_config;
        $this_config = $plugin_config['protect']['recipes_integration'];
        foreach( $members as $login => $rec ) 
    	{
    		
    		$s =  mysql_query(SELECT count(username)  FROM users WHERE username='$member[login]');
    		$count = mysql_result($s,0);
    		if($count==0)
    		{
    			//Add the user
    			$t =  mysql_query(INSERT INTO users VALUES(WHERE username='$member[login]');
    
    ......
    
    but as far as I can tell the $members only contains the loginname and the product array (per the referenced instructions) and so how do I get the password and email etc to add the new user to the integrated database.

    Do you recommend an easier way to get to what I am trying to do. Basically I want a c# application to call a web service that tells me whether the user has an active subscription and that is is....

    thanks... A
  2. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    Sure there is an easier way.

    PHP:
    <?php
    require_once './config.inc.php';

    $remotePw 'N3orgh43j';

    if (
    $_GET['remotePw'] != $remotePw)
       die(
    "Error: wrong password");
    if (empty(
    $_GET['login'])
       die(
    "Error: no username provided");

    $ul $db->users_find_by_string($_GET['login'], 'login'1);
    if (!
    count($ul)) 
       die(
    "Error: no users found with given login");

    $pl get_user_active_payments($ul[0]['member_id'], date('Y-m-d'));
    foreach (
    $pl as $p)
    {
        
    printf("Product#%d Starts:%s Expires:%s\r\n"$p['product_id], $p['begin_dat'], $p['expire_dat']);
    }
    Save this file as, say:
    http://www.yoursite.com/amember/remote-check.php

    it must be called from your C# application as
    http://www.yoursite.com/amember/remote-check.php?remotePw=N3orgh43j&login=bob
  3. Mogulbasher

    Mogulbasher New Member

    Joined:
    Aug 29, 2006
    Messages:
    2
    Cool, thanks, I ended up getting all the products and looping through them using foreach and converting the dates to a timestamp and then getting last valid expiry date which I brought back into the application and then did Simple AES encryption on that and store it as a variable in the settings class, for comparison while the app is running as this only meant a single ping against the server. I also on app first run require the data to register someone and add a free product registration into the amember database. Finally I put all the functions into a webservices WSDL

    PHP:
    include("config.inc.php");
        
    $q$db->query($sql "SELECT member_id FROM {$db->config[prefix]}members WHERE login = '$username' and pass='$password'");
        
    $member_id=getDataResult($q);
        
        
    $p=$db->get_user_payments($member_id$completed) ;
        
        
    $i 0;
        
    $validproduct =0;
        
    $finaltimestamp=0
        foreach (
    $p as $k => $v
        {
            
            foreach (
    $v as $y => $v2
            {
                    
    //echo "$y:$v2\n";
                
    if($y=='product_id')
                {
                    if(
    $v2==|| $v2==|| $v2==3)
                    {
                        
    $validproduct=1;
                    }
                }
                if(
    $y=='expire_date' && $validproduct==1)
                {
                    
    //echo 'date is '.$v2.'<br>';
                    
    list($year$month$day) = explode('-'$v2);
                    
    $timestamp mktime(000$month$day$year);
                    
                    if(
    $timestamp >$finaltimestamp)
                    {    
                        
    $finaltimestamp $timestamp;
                    }
                }
                
                }
                
    $validproduct=0;
            
    $i++;
        }

        
    $bestdate getdate($finaltimestamp);
        
    //print_r($bestdate);
        
    $result['year']=$bestdate['year'];
        
    $result['month']=sprintf("%02d"$bestdate['mon']);
        
    $result['day']=sprintf("%02d"$bestdate['mday']);
        return 
    $result;
    If there is something in there that is bad let me know...
    Many thanks works a treat.... Andrew
  4. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    There is a simpler solution :)

    PHP:
    <?php
    require './config.inc.php';
    $username $_GET['username'];

    echo 
    amDb()->selectCell("SELECT MAX(expire_date)
         FROM ?_payments p
            RIGHT JOIN ?_members u ON u.login=? AND p.member_id=u.member_id
       WHERE p.completed>0 AND p.product_id IN (?a)"

       
    $username
       array(
    1,2,3));
    // first ? replaced to [escaped] $username
    // second ?a replaced to 1,2,3 - product ids
    // max expiration date will be echo'ed

Share This Page