Zikula: A Flexible Open Source Content Management System
home | forum | contact us

Dizkus

Bottom
How I can extract or get the users name and email from PN?
  • Posted: 24.05.2004, 19:02
     
    edfel
    rank:
    Professional Professional
    registered:
     December 1969
    Status:
    offline
    last visit:
    02.09.07
    Posts:
    831
    Hi

    I need to extract username and real email from PN, How I can do it? I have phpMyAdmin but don't know how to do that. I need a csv file wth that information to be imported into another application.

    TIA
  • Posted: 26.05.2004, 10:06
     
    r3ap3r
    rank:
    Helper Helper
    registered:
     January 2004
    Status:
    offline
    last visit:
    22.02.08
    Posts:
    381
    I haven't taken the time to put any checks to see if people have comma's in their names or things like that so you will want to manually check the file that is created, but this will do it. Make sure you set the values in the first few lines to match your system.

    Code

    <?php
    $filename = "/tmp/myfilename.csv"; //set this to where you want the file written to
    $dbuser = "YourUsername";
    $dbpasswd = "YourPassword";
    $dbname = "Phoenix";  //set this to the database name (usually Phoenix)
    $dbhost="localhost"; //set it to the appropriate host if the database server is on a different machine
    // Connect to MySQL
    $dbi=mysql_connect($dbhost, $dbuser, $dbpasswd) or die ("Could not connect to MySQL.");
    mysql_select_db($dbname);
    $sql="SELECT pn_name, pn_email FROM nuke_users ORDER BY pn_name DESC";
    $result=mysql_query($sql);
    $emails="Name, EmailAddress\n";
    while($row=mysql_fetch_array($result))
    {
        $emails .=$row['pn_name'] . ',' . $row['pn_email']."\n";
    }
    mysql_close($dbi);
    $fhandle=fopen("$filename","w");
    fputs($fhandle,$emails);
    fclose($fhandle);
    echo "Done";
    ?>


    -Chris
  • Posted: 26.05.2004, 12:01
     
    Chestnut
    rank:
    Steering Committee Steering Committee
    registered:
     August 2002
    Status:
    offline
    last visit:
    03.03.08
    Posts:
    1221
    I'll just secure your code a little (file to be put at root) :

    Code

    <?php
    include 'includes/pnAPI.php';
    pnInit();

    list($dbconn) = pnDBGetConn();
    $pntable      = pnDBGetTables();

    $usertbl =  $pntable['users'];
    $usercol = &$pntable['users_column'];

    $filename = "/tmp/myfilename.csv"; //set this to where you want the file written to

    // You should consider taking the username (uname) as the name isn't always filled by the users.
    $sql = "SELECT   $usercol[name], $usercol[email]
            FROM     $pntable[users]
            ORDER BY $usercol[name] DESC"
    ;

    $result = $dbconn->Execute($sql);

    if ($dbconn->ErrorNo() <> 0) {
        echo "DB Error: ".$dbconn->ErrorNo().": ".$dbconn->ErrorMsg();
        exit();
    }

    $emails = "Name, EmailAddress\n";

    for (; !$result->EOF; $result->MoveNext()) {
        list($name, $email) = $result->fields;

        $emails .= $name . ',' . $email . "\n";

    }

    $result->Close();

    $fhandle = fopen("$filename","w");
    fputs($fhandle,$emails);
    fclose($fhandle);

    echo "Done";

    ?>


    ;)

    --
    Chestnut !
    Support via Private message won't be answered...
    http://dev.pnconcept.com
    http://www.postnuke-france.org
  • Posted: 26.05.2004, 12:26
     
    r3ap3r
    rank:
    Helper Helper
    registered:
     January 2004
    Status:
    offline
    last visit:
    22.02.08
    Posts:
    381
    I should have read his initial request a little closer. It looks like the username is what he wanted, my bad. So taking Chesnut's code and modifying it to give you what you want.

    Code

    <?php
     include 'includes/pnAPI.php';
     pnInit();
     
     list($dbconn) = pnDBGetConn();
     $pntable      = pnDBGetTables();
     
     $usertbl =  $pntable['users'];
     $usercol = &$pntable['users_column'];
     
     $filename = "/tmp/myfilename.csv"; //set this to where you want the file written to
     
      $sql = "SELECT   $usercol[uname], $usercol[email]
             FROM     $pntable[users]
             ORDER BY $usercol[uname] DESC"
    ;
     
     $result = $dbconn->Execute($sql);
     
     if ($dbconn->ErrorNo() <> 0) {
         echo "DB Error: ".$dbconn->ErrorNo().": ".$dbconn->ErrorMsg();
         exit();
     }
     
     $emails = "UserName, EmailAddress\n";
     
     for (; !$result->EOF; $result->MoveNext()) {
         list($uname, $email) = $result->fields;
     
         $emails .= $uname . ',' . $email . "\n";
     
     }
     
     $result->Close();
     
     $fhandle = fopen("$filename","w");
     fputs($fhandle,$emails);
     fclose($fhandle);
     
     echo "Done";
     
     ?>


    This is a smarter way of doing it. I just spit out some old code from my PHP-Nuke days :D

    -Chris
  • Posted: 26.05.2004, 12:31
     
    r3ap3r
    rank:
    Helper Helper
    registered:
     January 2004
    Status:
    offline
    last visit:
    22.02.08
    Posts:
    381
    As a side note: It could be considered a security threat to put this file in the root of your webserver where anyone who wanted could run it. You should protect it with some sort of .htaccess control.
    -Chris
  • Posted: 26.05.2004, 20:28
     
    edfel
    rank:
    Professional Professional
    registered:
     December 1969
    Status:
    offline
    last visit:
    02.09.07
    Posts:
    831
    Thanks!

    I will check it and put the file in a restricted area. I need the username _and_email. You guys make PostNuke the _BEST_.

    Later :wink:

Extensions Moderation

Main Menu

Extensions Database

Documentation

Development

Login

Donate to Zikula