Querying the a member database

Discussion in 'aMember Pro v.4' started by simplek, Mar 15, 2013.

  1. simplek

    simplek New Member

    Joined:
    May 2, 2012
    Messages:
    27
    Hey guys,

    I know this is a simple question but I don't think, how do i query the amember database.

    An example of what I put (from http://www.amember.com/docs/API/Db):
    require_once LIBRARY.'Am/Lite.php';
    require_once LIBRARY.'Am/Di.php';
    $users = Am_Di::getInstance()->db->select("SELECT * FROM ?_user WHERE state=? LIMIT ?d", 'NY', 10);

    I got this error:
    Fatal error: Class 'sfServiceContainerBuilder' not found in/home/justin/public_html/premium/library/Am/Di.phpon line164

    I found out that in Di.php,

    "class Am_Di extends sfServiceContainerBuilder"

    No idea why this class (sfServiceContainerBuilder) was not included...
  2. alex

    alex aMember Pro Customer Staff Member

    Joined:
    Jan 24, 2004
    Messages:
    6,021
    You mixes 2 different API: lite and full.

    Do the following instead:
    PHP:
    ini_set('display_errors'true);  // for debug time
    require_once '/path/to/amember/bootstrap.php';
    $di  Am_Di::getInstance(); // get a shortcut
    $users $di->userTable->findByState('NY');
    foreach (
    $users as $user)
    {
      
    // got an array of User objects
      
    echo $user->login;
    }
    // or another try
    $users $di->db->select("SELECT * FROM ?_users WHERE state=? LIMIT ?d"'NY'10);
    // got array of MySQL records (arrays)
    var_dump($users);
     
  3. simplek

    simplek New Member

    Joined:
    May 2, 2012
    Messages:
    27
    I deleted my file and copy and pasted the exact code. There seems do be something wrong with bootstrap.php. I'm pretty sure I got the right path to file. I got the following error...

    Script Error
    An internal error happened in the script, please contact webmaster for details

    When I uncomment bootstrap the php and all the code after it, there is no error.
  4. alexander

    alexander Administrator Staff Member

    Joined:
    Jan 8, 2003
    Messages:
    6,279
    Make sure that you have no php output or html code before this line:
    require_once '/path/to/amember/bootstrap.php';
    aMember starts session from bootstrap.php and if you have HTML code before this, script will generate an error.
  5. simplek

    simplek New Member

    Joined:
    May 2, 2012
    Messages:
    27
    That was it! Thanks!

Share This Page