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

Drilling Deeper - 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
You can also get fancy by adding selection criteria in your call to getUsers(), as a second argument to the method. Consider the following variant of the example above, which only returns records of those users who are male and between 18 and 25:


<?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"), array( array("field" => "sex", "value" => "M", "match" => "exact"), array("field" => "age", "value" => array(18,25), "match" => "between") ) ); // 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, the second argument to the getUsers() method - a series of nested arrays containing selection criteria - provides patUser with a list of additional conditions to be satisfied when querying the database. Only those user records that match the specified conditions will be included in the result.

Here's the output:



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

blog comments powered by Disqus
   

PHP ARTICLES

- 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...
- PHP: Building Concrete Validators
- Sanitizing Input with PHP
- Executing Shell Commands with PHP
- Handling File Data with PHP
- File Security and Resources with PHP
- ArrayObject PHP Class Examples
- ArrayObject PHP Class: An Introduction
- Getting File System Data with PHP
- PHP Tools for Working with the File and Oper...
- Working with the File and Operating System w...
- PHP Proxy Patterns: Completing a Blog


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 2 - Follow our Sitemap

Dev Shed Tutorial Topics: