Home arrow PHP arrow Page 6 - User Authentication With patUser (part 2)

Accounting For Change - PHP

In this second part, find out how you can use the patUser API toview, add, edit and delete users (and user attributes) from your userdatabase.

TABLE OF CONTENTS:
  1. User Authentication With patUser (part 2)
  2. Meeting The Family
  3. Asking For More
  4. Drilling Deeper
  5. All For One, And One For All
  6. Accounting For Change
  7. California Calling
  8. Making New Friends
  9. A Fast Edit
  10. Here Today, Gone Tomorrow
  11. Connecting The Dots
  12. A Well-Formed Plan
  13. Slice And Dice
By: icarus, (c) Melonfire
Rating: starstarstarstarstar / 7
May 01, 2003

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
The default patUser-supplied database schema for the "groups" table includes only two group attributes: its name, and a unique group ID. Most of the time, this is sufficient; however, in case you need to add more attributes, patUser can be easily tweaked to work with this extra data.

Let's alter the default "groups" table to include some additional fields, for description and location:


# # Table structure for table `groups` # CREATE TABLE groups ( gid int(11) NOT NULL auto_increment, name varchar(50) default NULL, dsc varchar(255) NOT NULL default '', loc varchar(255) NOT NULL default '', UNIQUE KEY gid (gid) ) TYPE=MyISAM;
While we're at it, let's also insert a few records into the new table:

INSERT INTO groups (gid, name, dsc, loc) VALUES (1, 'Accounts', 'Billing and finance activities', 'AZ'); INSERT INTO groups (gid, name, dsc, loc) VALUES(2, 'Administration', 'Administrative activities', 'CA'); INSERT INTO groups(gid, name, dsc, loc) VALUES (3, 'Operations', 'Logistics and operations','CA');
As before, I can retrieve this information via an SQL query,

mysql> SELECT * FROM groups; +-----+----------------+--------------------------------+-----+| gid | name | dsc | loc |+-----+----------------+--------------------------------+-----+| 1 | Accounts | Billing and finance activities | AZ || 2 | Administration | Administrative activities | CA || 3 | Operations | Logistics and operations | CA |+-----+----------------+--------------------------------+-----+3 rows in set (0.00 sec)
or have patUser do it for me via its getGroups() function:

<?php // include classesinclude("../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", "dsc", "loc"));// print as tableecho "<h2>Groups</h2>";echo "<table border=1>";echo "<tr>";echo "<td><b>GID</b></td>";echo "<td><b>Name</b></td>";echo "<td><b>Description</b></td>";echo "<td><b>Location</b></td>";echo "</tr>";// iterate over listforeach ($list as $l){ echo "<tr>"; echo "<td>" . $l['gid'] . "</td>"; echo "<td>" . $l['name'] . "</td>"; echo "<td>" . $l['dsc'] . "</td>"; echo "<td>" . $l['loc'] . "</td>"; echo "</tr>";}echo "</table>";?>


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

blog comments powered by Disqus
escort Bursa Bursa escort Antalya eskort
   

PHP ARTICLES

- Hackers Compromise PHP Sites to Launch Attac...
- Red Hat, Zend Form OpenShift PaaS Alliance
- PHP IDE News
- BCD, Zend Extend PHP Partnership
- PHP FAQ Highlight
- PHP Creator Didn't Set Out to Create a Langu...
- PHP Trends Revealed in Zend Study
- PHP: Best Methods for Running Scheduled Jobs
- PHP Array Functions: array_change_key_case
- PHP array_combine Function
- PHP array_chunk Function
- PHP Closures as View Helpers: Lazy-Loading F...
- Using PHP Closures as View Helpers
- PHP File and Operating System Program Execut...
- PHP: Effects of Wrapping Code in Class Const...

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: