PHP
  Home arrow PHP arrow Page 5 - User Authentication With patUser (part 2)
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

User Authentication With patUser (part 2)
By: icarus, (c) Melonfire
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 7
    2003-05-01


    Table of Contents:
  • User Authentication With patUser (part 2)
  • Meeting The Family
  • Asking For More
  • Drilling Deeper
  • All For One, And One For All
  • Accounting For Change
  • California Calling
  • Making New Friends
  • A Fast Edit
  • Here Today, Gone Tomorrow
  • Connecting The Dots
  • A Well-Formed Plan
  • Slice And Dice

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    User Authentication With patUser (part 2) - All For One, And One For All
    ( Page 5 of 13 )

    patUser also allows you to organize users into named collections or groups. You might remember, from the discussion of the patUser database schema in the previous segment of this article, that there are two tables designed specifically for this task, the "groups" table (which maintains a list of available groups) and the "usergroups" table (which maintains a list of which users belong to which group).

    Here's the schema for the "groups" tables:


    # # Table structure for table 'groups' # CREATE TABLE groups ( gid int(11) NOT NULL auto_increment, name varchar(50), UNIQUE gid (gid) );
    Let's now add a couple of groups to the system,

    INSERT INTO groups (gid, name) VALUES (1, 'Accounts'); INSERT INTO groups (gid, name) VALUES (2, 'Administration'); INSERT INTO groups (gid, name) VALUES (3, 'Operations');
    and verify that they have been added correctly via an SQL query:

    mysql> SELECT * FROM groups; +-----+----------------+ | gid | name | +-----+----------------+ | 1 | Accounts | | 2 | Administration | | 3 | Operations | +-----+----------------+ 3 rows in set (0.04 sec)
    Obviously, we can perform the same task using patUser's getGroups() function, which works in much the same way as the getUsers() function discussed on the previous page. The following code listing demonstrates:

    <?php // include classes include("../include/patDbc.php"); include("../include/patUser.php"); // initialize database layer $db = new patMySqlDbc("localhost", "db211", "us111", "secret"); // initialize patUser $u = new patUser(true); // connect patUser to database $u->setAuthDbc($db); // set tables $u->setAuthTable("users"); $u->setGroupTable("groups"); // get group list $list = $u->getGroups(array("gid", "name")); // uncomment this to see data structure // print_r($list); // print as list echo "<h2>Groups</h2>"; echo "<ul>"; foreach ($list as $l) { echo "<li>" . $l['name'] . " (" . $l['gid'] . ")"; } echo "</ul>"; ?>
    Here's the output:



    Note the introduction of a new method in the script above, setGroupTable(). This method, together with the setGroupFields()method, allows you to configure patUser to use a different set of tables than its default by remapping the default table and column references to custom values.

     
     
    >>> More PHP Articles          >>> More By icarus, (c) Melonfire
     

       

    PHP ARTICLES

    - Building Dynamic Queries with Chainable Meth...
    - PHP Encryption and Decryption Methods
    - Building a MySQL Abstraction Class with Meth...
    - Completing a Sample String Processor with Me...
    - Mastering WHILE Loops for PHP and MySQL
    - Method Chaining: Adding More Methods to the ...
    - Method Chaining in PHP 5
    - The Role of Interfaces in Applying the Depen...
    - Dependency Injection: Using a Setter Method ...
    - Using a Model Class with the Dependency Inje...
    - Injecting Objects Using Setter Methods with ...
    - Injecting Objects by Constructor with the De...
    - The Dependency Injection Design Pattern in P...
    - Performing Inferential Statistical Analysis ...
    - Performing Descriptive Statistical Analysis ...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 1 Hosted by Hostway
    Stay green...Green IT