table_stock.class.php 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * 数据库表:管理员组
  4. *
  5. * @createtime 2018/03/01
  6. * @author 空竹
  7. * @copyright 芝麻开发(http://www.zhimawork.com)
  8. */
  9. class Table_stock extends Table {
  10. protected $table_name = 'stock';//表名,不带前缀,前缀在config中定义
  11. protected $table_id = 'stock_id';//指定ID字段名称,必须
  12. protected $table_status = '';//指定状态字段名称,如果有
  13. protected $table_order = '';//指定排序字段名称,如果有
  14. //数据库结构
  15. protected function struct(){
  16. $attr = array();
  17. $attr['id'] = 'stock_id';
  18. $attr['code'] = 'stock_code';
  19. $attr['name'] = 'stock_name';
  20. $attr['exchange'] = 'stock_exchange';
  21. $attr['sector'] = 'stock_sector';
  22. return $attr;
  23. }
  24. public function add($attr){
  25. $param = array (
  26. 'stock_code' => array('string', $attr['code']),
  27. 'stock_name' => array('string', $attr['name']),
  28. 'stock_exchange' => array('string', $attr['exchange']),
  29. 'stock_sector' => array('number', $attr['sector']),
  30. );
  31. return $this->pdo->sqlinsert($this->table_fullname, $param);
  32. }
  33. public function getInfoByCode($code){
  34. //查询语句必须用sql_check_input检查参数
  35. $code = trim($code);
  36. $code = $this->pdo->sql_check_input(array('string', $code));
  37. $sql = "select * from ". $this->table_fullname ." where stock_code = $code limit 1";
  38. $rs = $this->pdo->sqlQuery($sql);
  39. $r = array();
  40. if($rs){
  41. foreach($rs as $key => $val){
  42. $r[$key] = $this->dataToAttr($val);
  43. }
  44. return $r[0];
  45. }else{
  46. return $r;
  47. }
  48. }
  49. }
  50. ?>