Re: How to reference existing DB in Auth?
| From: | \[php\]Walter | Date: | Thu, 20 May 2004 15:27:26 +0000 |
| Subject: | Re: How to reference existing DB in Auth? | ||
| References: | 1 | Groups: | php.pear.general |
| Request: | Send a blank email to pear-general+get-12659@lists.php.net to get a copy of this message | ||
This is what I use...
Walter
========================
// **** DB Class setup
// What kind of database server are we connecting too?
$db_type = 'mysql';
// local connectivity data
$db_host = 'localhost';
$db_user = 'auth';
$db_pass = 'auth';
$db_name = 'auth';
$db_table = 'auth';
// Data Source Name: This is the universal connection string
$dsn = "$db_type://$db_user:$db_pass@$db_host/$db_name";
// DB::connect will return a PEAR DB object on success
// or an PEAR DB Error object on error
$objDB = DB::connect($dsn);
// With DB::isError you can differentiate between an error or
// a valid connection.
if (DB::isError($objDB))
die ($objDB->getMessage());
// **** Class Class setup
// Call Authentiction Class Libraries
require_once("Auth.php");
// Parameters for DB access in Auth
// $dsn and $db_table are defined in the DB access INC file
// NOTE: This uses the new DB container patch by Mattias Guns
// It accepts a DB Object now, instead opening the DB itself!
// Container::DB::_parseOptions() patch
$params = array( "DB" => &$objDB, // DB Object
//"dsn" => $dsn, // DSN string for new DB Object
"table" => $db_table, // which table do we hit?
"usernamecol" => "username", // field name for user id
"passwordcol" => "password", // field name for user password
"db_fields" => array('*') // which other fields are you interested
in?
);
// A database is used as storage container in this example
$objAuth = &new Auth("DB", $params, 'login');
// Open existing 'session' for this page
$objAuth->start();
// Do we have a proper session
$bolRet = $objAuth->getAuth();
if (Pear::isError($bolRet))
// We failed for some reason, bale
header("Location:failed.php");
else
// We're in! Now go somewhere else!
header("Location:success.php");
// eof