2
0

function.php 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. require_once "../path.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 group_info WHERE id=?";
  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, "", "", array(PDO::ATTR_PERSISTENT => true));
  29. $this->dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
  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 group_info WHERE id= ? ";
  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. if (empty($id)) {
  61. return "";
  62. }
  63. if (isset($parentId[$id])) {
  64. return $parentId[$id];
  65. }
  66. if ($this->dbh) {
  67. $query = "SELECT parent FROM group_info WHERE id= ? ";
  68. $stmt = $this->dbh->prepare($query);
  69. $stmt->execute(array($id));
  70. $user = $stmt->fetch(PDO::FETCH_ASSOC);
  71. if ($user) {
  72. $parentId[$id] = $user["parent"];
  73. return $parentId[$id];
  74. } else {
  75. $parentId[$id] = "";
  76. return $parentId[$id];
  77. }
  78. } else {
  79. $parentId[$id] = "";
  80. return $parentId[$id];
  81. }
  82. }
  83. }