插件62:从表中读取信息

<?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));
}

?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值