<?php // Plug-in 62: Get User From DB
/*
* 插件说明:
* 根据提供的表名和用户名,插件将读取这个用户的记录并返回给调用程序。
* 若操作成功,则返回一个两元素的数组,其中第一个元素的值为TRUE,而第二个元素是一个数组,保存用户的各项数据。
* 若操作失败,则返回一个元素数组,这个元素的值为FALSE.
* 他需要的参数:
* $table 数据表名。
* $handle 用户名。
*/
// This is an executable example with additional code supplied
// To obtain just the plug-ins please click on the Download link
$dbhost = 'localhost'; // Normally no need to change this
$dbname = 'piphp'; // Change to your database name
$dbuser = 'root'; // Change to your database user name
$dbpass = 'xiaonan'; // Change to your database password
mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());
mysql_select_db($dbname) or die(mysql_error());
$table = 'Users';
$handle = 'firstprez';
$result = PIPHP_GetUserFromDB($table, $handle);
echo "<pre>";
if ($result[0] == FALSE) echo "Lookup failed.";
else echo "Name = " . $result[1][0] . "<br />" .
"Handle = " . $result[1][1] . "<br />" .
"Pass(salted) = " . $result[1][2] . "<br />" .
"Email = " . $result[1][3];
function PIPHP_GetUserFromDB($table, $handle)
{
// Plug-in 62: Get User From DB
//
// This plug-in accepts a username in $handle and then
// returns all details (if any) held for that handle.
// On success it returns a two element array with the
// first element being TRUE and the second the array of
// user details. On failure it returns a single element
// array with the value FALSE. It expects these
// arguments:
//
// $table: The table name within $dbname
// $handle: The user's handle or username
$query = "SELECT * FROM $table WHERE handle='$handle'";
$result = mysql_query($query);
if (mysql_num_rows($result) == 0) return array(FALSE);
else return array(TRUE, mysql_fetch_array($result, MYSQL_NUM));
}
?>