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

Making New Friends - 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
It's just as simple to add new users and groups to the system - all you need to do is use patUser's addUser() and addGroup() methods, which accept an array of field-value pairs and uses them to create a new user or group record in the database. Both methods return the ID of the newly-created user or group if successful. Consider the following example, which demonstrates how to add new users:


<?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"); // add user $uid = $u->addUser( array("username" => "tom", "passwd" => "tom") ); // check to see if user added and display message if ($uid) { echo "User successfully added with UID $uid"; } else { echo "User could not be added!"; } ?>
By default, patUser automatically logs the newly-created user into the system. You can avoid this by specifying a second argument to addUser(), as in the example below:

<?php $u->addUser( array("username" => "tom", "passwd" => "tom"), false ); ?>
In a similar manner, a new group may be added - here's how:

<?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 table$u->setGroupTable("groups");// add group$gid = $u->addGroup( array("name" => "Human Resources") );// check to see if group added and display messageif ($gid){ echo "Group successfully added with GID $gid";}else{ echo "Group could not be added!";}?>


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