table_baseconfig.class.php 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. $attr['addtime'] = 'baseconfig_addtime';
  22. return $attr;
  23. }
  24. public function getInfoByKey($key)
  25. {
  26. $key = $this->pdo->sql_check_input(array('string', $key));
  27. $sql = "select * from " . $this->table_fullname . " where baseconfig_key = $key limit 1";
  28. $rs = $this->pdo->sqlQuery($sql);
  29. $r = array();
  30. if ($rs) {
  31. foreach ($rs as $key => $val) {
  32. $r[$key] = $this->dataToAttr($val);
  33. }
  34. return $r[0];
  35. } else {
  36. return $r;
  37. }
  38. }
  39. public function add($attr)
  40. {
  41. $param = array(
  42. 'baseconfig_key' => array('string', $attr['key']),
  43. 'baseconfig_value' => array('string', $attr['value']),
  44. 'baseconfig_addtime' => array('number', time()),
  45. );
  46. return $this->pdo->sqlinsert($this->table_fullname, $param);
  47. }
  48. public function update($id, $attr)
  49. {
  50. $param = array(
  51. 'baseconfig_key' => array('string', $attr['key']),
  52. 'baseconfig_value' => array('string', $attr['value']),
  53. 'baseconfig_addtime' => array('number', time()),
  54. );
  55. $where = array(
  56. 'baseconfig_id' => array('number', $id)
  57. );
  58. return $this->pdo->sqlupdate($this->table_fullname, $param, $where);
  59. }
  60. }