table_baseconfig.class.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: wangming
  5. * Date: 2019/1/22
  6. * Time: 20:54
  7. */
  8. class Table_baseconfig extends Table
  9. {
  10. protected $table_name = 'baseconfig';//表名
  11. protected $table_id = 'baseconfig_id';//指定ID字段名称,必须
  12. protected $table_status = '';//指定状态字段名称,如果有
  13. protected $table_order = '';//指定排序字段名称,如果有
  14. //数据库结构
  15. protected function struct()
  16. {
  17. $attr = array();
  18. $attr['id'] = 'baseconfig_id';
  19. $attr['key'] = 'baseconfig_key';
  20. $attr['value'] = 'baseconfig_value';
  21. return $attr;
  22. }
  23. public function getInfoByKey($key)
  24. {
  25. $key = $this->pdo->sql_check_input(array('string', $key));
  26. $sql = "select * from " . $this->table_fullname . " where baseconfig_key = $key limit 1";
  27. $rs = $this->pdo->sqlQuery($sql);
  28. $r = array();
  29. if ($rs) {
  30. foreach ($rs as $key => $val) {
  31. $r[$key] = $this->dataToAttr($val);
  32. }
  33. return $r[0];
  34. } else {
  35. return $r;
  36. }
  37. }
  38. public function add($attr)
  39. {
  40. $param = array(
  41. 'baseconfig_key' => array('string', $attr['key']),
  42. 'baseconfig_value' => array('string', $attr['value']),
  43. );
  44. return $this->pdo->sqlinsert($this->table_fullname, $param);
  45. }
  46. public function update($id, $attr)
  47. {
  48. $param = array(
  49. 'baseconfig_key' => array('string', $attr['key']),
  50. 'baseconfig_value' => array('string', $attr['value']),
  51. );
  52. $where = array(
  53. 'baseconfig_id' => array('number', $id)
  54. );
  55. return $this->pdo->sqlupdate($this->table_fullname, $param, $where);
  56. }
  57. }