function.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. <?php
  2. require_once "../config.php";
  3. require_once "../public/_pdo.php";
  4. require_once '../public/function.php';
  5. require_once '../ucenter/function.php';
  6. function group_get_name($id)
  7. {
  8. if (isset($id)) {
  9. PDO_Connect(_FILE_DB_GROUP_);
  10. $query = "SELECT name FROM "._TABLE_GROUP_INFO_." WHERE uid=?";
  11. $Fetch = PDO_FetchRow($query, array($id));
  12. if ($Fetch) {
  13. return $Fetch["name"];
  14. } else {
  15. return "";
  16. }
  17. } else {
  18. return "";
  19. }
  20. }
  21. class GroupInfo
  22. {
  23. private $dbh;
  24. private $buffer;
  25. public function __construct()
  26. {
  27. $dns = _FILE_DB_GROUP_;
  28. $this->dbh = new PDO($dns, _DB_USERNAME_, _DB_PASSWORD_, array(PDO::ATTR_PERSISTENT => true));
  29. $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  30. $buffer = array();
  31. $parentId = array();
  32. }
  33. public function getName($id)
  34. {
  35. if (empty($id)) {
  36. return "";
  37. }
  38. if (isset($buffer[$id])) {
  39. return $buffer[$id];
  40. }
  41. if ($this->dbh) {
  42. $query = "SELECT name FROM "._TABLE_GROUP_INFO_." WHERE uid= ? ";
  43. $stmt = $this->dbh->prepare($query);
  44. $stmt->execute(array($id));
  45. $user = $stmt->fetch(PDO::FETCH_ASSOC);
  46. if ($user) {
  47. $buffer[$id] = $user["name"];
  48. return $buffer[$id];
  49. } else {
  50. $buffer[$id] = "";
  51. return $buffer[$id];
  52. }
  53. } else {
  54. $buffer[$id] = "";
  55. return $buffer[$id];
  56. }
  57. }
  58. public function getParentId($id)
  59. {
  60. /*
  61. */
  62. return 0;
  63. if (empty($id)) {
  64. return "";
  65. }
  66. if (isset($parentId[$id])) {
  67. return $parentId[$id];
  68. }
  69. if ($this->dbh) {
  70. $query = "SELECT parent FROM "._TABLE_GROUP_INFO_." WHERE uid= ? ";
  71. $stmt = $this->dbh->prepare($query);
  72. $stmt->execute(array($id));
  73. $user = $stmt->fetch(PDO::FETCH_ASSOC);
  74. if ($user) {
  75. $parentId[$id] = $user["parent"];
  76. return $parentId[$id];
  77. } else {
  78. $parentId[$id] = "";
  79. return $parentId[$id];
  80. }
  81. } else {
  82. $parentId[$id] = "";
  83. return $parentId[$id];
  84. }
  85. }
  86. }