Simple way to Connect to MYSQL DB in Amember 4

Discussion in 'aMember Pro v.4' started by amemberfan9, Apr 22, 2012.

  1. amemberfan9

    amemberfan9 New Member

    Joined:
    Sep 8, 2011
    Messages:
    9
    Hi,

    I just started creating my own script and I use the Lite.php at the top of my php page. What I'm trying to do is pull information from Lite such as the $USERID below to run my script and insert and update other mysql tables that I have created within amember.

    $USEID = Am_Lite::getInstance()->getId();

    I have not touched any of the amember tables but I want to for example run a mysql_query that updates 'my_unique_table' and inserts $USEID and other key information that I'd get from Lite.php.

    I'm just trying to figure out how to connect to the db, the Generic.php did not help and I have been spending hours trying to run various functions from the API and nothing works, all that seemingly works in using Lite to get various info like getId above.

    Thanks
  2. thehpmc

    thehpmc Member

    Joined:
    Aug 24, 2006
    Messages:
    901
    If you are talking about a stand alone style script to insert data into your own database/table then would suggest something along the lines of:
    PHP:
    <?php
    $dbname
    ="";  // Values for your database, if same as aMember database copy from application/config.php
    $user="";        // Or simply include the application/config.php file in this script and replace these lines
    $pass="";

    $sql=              //Construct row for entry into your database
    "INSERT INTO my_unique_table
    $USEID;
    $other_data;
    $other_data;
    $other_data;
    $other_data    //Assuming 5 columns in your database table
    "

    try {
      
    $db_conn = new PDO('mysql:host=localhost;dbname='.$dbname$user$pass);
    }
    catch (
    PDOException $e) {
      echo 
    "Could not connect to database";
      }
    // perform query
    $stmt $db_conn->query($sql);
    $stmp=0//Close database connection
    ?>
    Save this as a php file to be called as required.

    This is NOT intended to be a working script but simply collection of ideas, thrown together, of how, what, I think, you are wanting, could be achieved.

    Bear in mind you only gave a simple outline of your thoughts. More than one row entered at a time would require a FOR or WHILE loop.

Share This Page