PHP
  Home arrow PHP arrow Page 3 - 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) - Asking For More
    ( Page 3 of 13 )

    Now, let's make some additions to the patUser-provided schema for the "users" table. You might remember that the original schema looked like this:



    # # Table structure for table 'users' # CREATE TABLE users ( uid int(10) unsigned NOT NULL auto_increment, username varchar(20) NOT NULL default '', passwd varchar(20) NOT NULL default '', email varchar(200) default NULL, nologin tinyint(1) NOT NULL default '0', first_login datetime default NULL, last_login datetime default NULL, count_logins int(10) unsigned NOT NULL default '0', count_pages int(10) unsigned NOT NULL default '0', time_online int(11) NOT NULL default '0', PRIMARY KEY (uid), KEY username (username) ) TYPE=MyISAM;
    Let's alter this to include some additional fields, for age, sex and telephone number:

    CREATE TABLE users ( uid int(10) unsigned NOT NULL auto_increment, username varchar(20) NOT NULL default '', passwd varchar(20) NOT NULL default '', email varchar(200) default NULL, age tinyint(4) NOT NULL default '0', sex char(1) NOT NULL default '', tel varchar(50) NOT NULL default '', nologin tinyint(1) NOT NULL default '0', first_login datetime default NULL, last_login datetime default NULL, count_logins int(10) unsigned NOT NULL default '0', count_pages int(10) unsigned NOT NULL default '0', time_online int(11) NOT NULL default '0', PRIMARY KEY (uid), KEY username (username) ) TYPE=MyISAM;
    While we're at it, let's also insert a few records into the new table:

    INSERT INTO users (uid, username, passwd, email, age, sex, tel) VALUES (1, 'joe', 'joe', NULL, 19, 'M', '123 4567'); INSERT INTO users (uid, username, passwd, email, age, sex, tel) VALUES (2, 'sarah', 'sarah', NULL, 35, 'F', '543 18238'); INSERT INTO users (uid, username, passwd, email, age, sex, tel) VALUES (3, 'john', 'john', 'john@some.domain.com', 22, 'M', '853 2377'); INSERT INTO users (uid, username, passwd, email, age, sex, tel) VALUES (4, 'william', 'william', 'william@somewhere.com', 31, 'M', '123 2372');
    As before, I can retrieve this information via an SQL query,

    mysql> SELECT uid, username, age, sex, tel FROM users; +-----+----------+-----+-----+-----------+ | uid | username | age | sex | tel | +-----+----------+-----+-----+-----------+ | 1 | joe | 19 | M | 123 4567 | | 2 | sarah | 35 | F | 543 18238 | | 3 | john | 22 | M | 853 2377 | | 4 | william | 31 | M | 123 2372 | +-----+----------+-----+-----+-----------+ 4 rows in set (0.00 sec)
    or have patUser do it for me via its getUsers() function:

    <?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 table $u->setAuthTable("users"); // get user list $list = $u->getUsers(array("uid", "username", "age", "sex", "tel")); // print as table echo "<h2>Users</h2>"; echo "<table border=1>"; echo "<tr>"; echo "<td><b>UID</b></td>"; echo "<td><b>Username</b></td>"; echo "<td><b>Age</b></td>"; echo "<td><b>Sex</b></td>"; echo "<td><b>Tel</b></td>"; echo "</tr>"; // iterate over list foreach ($list as $l) { echo "<tr>"; echo "<td>" . $l['uid'] . "</td>"; echo "<td>" . $l['username'] . "</td>"; echo "<td>" . $l['age'] . "</td>"; echo "<td>" . $l['sex'] . "</td>"; echo "<td>" . $l['tel'] . "</td>"; echo "</tr>"; } echo "</table>"; ?>
    In this case, I've told getUsers() to retrieve a few extra fields from the database - specifically, the "age", "sex" and "tel" fields. You'll remember these are not standard patUser fields, but have been added by me for illustrative purposes.

    Here's the output:



     
     
    >>> 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