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

Meeting The Family - 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
Let's start with the basics - obtaining a list of current users from the database. If you've been following along, you already know that right now, the database has only a single user, "joe". Let's add a couple more:



INSERT INTO users ('uid', 'username', 'passwd') VALUES ('', 'sarah', 'sarah'); INSERT INTO users ('uid', 'username', 'passwd') VALUES ('', 'john', 'john');
You can verify the result with a quick SQL query to the "users" table:

mysql> SELECT uid, username FROM users; +-----+----------+| uid | username |+-----+----------+| 1 | joe || 2 | sarah || 3 | john |+-----+----------+3 rows in set (0.00 sec)
Now, let's try doing the same with patUser:

<?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->setAuthTable("users");// get user list$list = $u->getUsers(array("uid", "username"));// uncomment this to see data structure// print_r($list);// print as listecho "<h2>Users</h2>";echo "<ul>";foreach ($list as $l){ echo "<li>" . $l['username'] . " (" . $l['uid'] . ")";}echo "</ul>";?>
The first part of this script should be easily recognizable to you by now - it consists of the code needed to instantiate a patUser object instance and prepare it for use. Once the object has been prepared, the getUsers() function is used to retrieve a list of all the users in the database. The return value of the getUsers() method is an associative array containing user records, one element for each record.

The first argument to the getUsers() function is an array containing the names of the fields to be included in the result set - these field names appear as keys in the returned array, and can be used to access the corresponding values. Here's the output:



You're not restricted to using just the default fields built into the patUser database schema - you can just as easily add your own. Find out how, on the next page.

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