pdo->sql_check_input(array('string', $code));//类型是字符串,那一定要在条件中将数据使用引号引用起来,否则不使用索引 $sql = "select * from ". $this->table_fullname ." where 1=1 "; $where =" and index_day_k_code=".$stock_code." and index_day_k_date <=".$start_date ; $sql.=$where; $orderInfo=" ORDER BY index_day_k_date desc"; $sql.=$orderInfo; $limit=" limit ".$traceback_days; $sql.=$limit; if($order==1){ $sql= " SELECT a.* FROM "."($sql) a ORDER BY a.index_day_k_date desc "; }else{ $sql= " SELECT a.* FROM "."($sql) a ORDER BY a.index_day_k_date asc"; } $rs = $this->pdo->sqlQuery($sql); $r = array(); if($rs){ foreach($rs as $key => $val){ $r[$key] = $this->dataToAttr($val); } return $r; }else{ return $r; } } /*** * @param $code * @param $date * @return array * wanggangtao * 获取某天的指数代码 */ public function get_current_day_index($code,$date) { //查询语句必须用sql_check_input检查参数 $stock_code = $this->pdo->sql_check_input(array('string', $code));//类型是字符串,那一定要在条件中将数据使用引号引用起来,否则不使用索引 $sql = "select * from ". $this->table_fullname ; $where=" where 1=1 "; $where.=" and index_day_k_code=".$stock_code ; if($date==0){//获取的是当天的数据,最近一天的交易日的数据 $date = date("Ymd",time()); $where.=" and index_day_k_date <= ".$date; }else{//获取某一天的数据,不是交易日则返回空 $date = $this->pdo->sql_check_input(array('number', $date)); $where.=" and index_day_k_date =".$date; } $sql.=$where; $order=" order by index_day_k_date desc limit 1 "; $sql.=$order; $rs = $this->pdo->sqlQuery($sql); $r = array(); if($rs){ foreach($rs as $key => $val){ $r[$key] = $this->dataToAttr($val); } return $r; }else{ return $r; } } /**** * @param $start_date * @param $end_date * @param $index_type * @param $num * @param $order_info * @return array * wanggangtao */ public function getIndexListHistroy($code,$start_date,$end_date,$order_info) { //查询语句必须用sql_check_input检查参数 $stock_code= $this->pdo->sql_check_input(array('string', $code)); $start_date= $this->pdo->sql_check_input(array('number', $start_date)); $end_date = $this->pdo->sql_check_input(array('number', $end_date)); $sql = "select * from ". $this->table_fullname ." where 1=1 "; $sql.=" and index_day_k_code=".$stock_code ; $where =" and index_day_k_date >= ".$start_date." and index_day_k_date<=".$end_date ; $sql.=$where; if($order_info==1){ $order=" order by index_day_k_date desc "; }else{ $order=" order by index_day_k_date asc "; } $sql.=$order; $rs = $this->pdo->sqlQuery($sql); $r = array(); if($rs){ foreach($rs as $key => $val){ $r[$key] = $this->dataToAttr($val); } return $r; }else{ return $r; } } public function add($attr){ $param = array ( 'index_day_k_timestamp' => array('number', $attr['timestamp']), 'index_day_k_date' => array('number', $attr['date']), 'index_day_k_code' => array('string', $attr['code']), 'index_day_k_name' => array('string', $attr['name']), 'index_day_k_open_price' => array('number', $attr['open_price']), 'index_day_k_close_price' => array('number', $attr['close_price']), 'index_day_k_highest_price' => array('number', $attr['highest_price']), 'index_day_k_lowest_price' => array('number', $attr['lowest_price']), 'index_day_k_increase_price' => array('number', $attr['increase_price']), 'index_day_k_increase_ratio' => array('number', $attr['increase_ratio']), 'index_day_k_amount' => array('number', $attr['amount']), 'index_day_k_value' => array('number', $attr['value']), ); return $this->pdo->sqlinsert($this->table_fullname, $param); } /*** * @param $attr * @return mixed * 历史指数数据 */ public function insert($attr){ $param = array ( 'index_day_k_timestamp' => array('number', $attr['timestamp']), 'index_day_k_date' => array('number', $attr['date']), 'index_day_k_code' => array('string', $attr['code']), 'index_day_k_name' => array('string', $attr['name']), 'index_day_k_open_price' => array('number', $attr['open_price']), 'index_day_k_close_price' => array('number', $attr['close_price']), 'index_day_k_highest_price' => array('number', $attr['highest_price']), 'index_day_k_lowest_price' => array('number', $attr['lowest_price']), 'index_day_k_increase_price' => array('number', $attr['increase_price']), 'index_day_k_increase_ratio' => array('number', $attr['increase_ratio']), 'index_day_k_amount' => array('number', $attr['amount']), 'index_day_k_value' => array('number', $attr['value']), ); return $this->pdo->sqlinsert($this->table_fullname, $param); } } ?>