db = DB::connect($this->dbtype."://" .$this->dbuser . ":" . $this->dbpass . "@" . $this->dbhost . "/" . $this->dbname); if (DB::isError($this->db)) { error_log('Standard Message: ' . $this->db->getMessage() . "\n"); error_log('Standard Code: ' . $this->db->getCode() . "\n"); error_log('DBMS/User Message: ' . $this->db->getUserInfo() . "\n"); error_log('DBMS/Debug Message: ' . $this->db->getDebugInfo() . "\n"); } $this->db->setFetchMode(DB_FETCHMODE_ASSOC); } function insert_gpsinfo($mob_id, $data) { $lat = preg_replace('/^\+/','',$data{'lat'}); $lng = preg_replace('/^\+/','',$data{'lon'}); $lat = $this->trans_latlng($lat); $lng = $this->trans_latlng($lng); foreach (array("mob_gps", "mob_gps_recent") as $table) { $sql = "replace into ${table} (mob_id, time, lat, lng, gps_info) values (?,?,?,?,?)"; $sth = $this->db->prepare($sql); $res = $this->db->execute($sth, array( $mob_id, $data{'time'}, $lat, $lng, serialize($data) )); if($res != DB_OK) { error_log("ERR in insert_gpsinfo (${table})"); return false; } } return true; } function get_recent_users() { $sql = "select mob_id, time, lat, lng from mob_gps_recent"; return $this->db->getAll($sql); } function get_user($mob_id) { $sql = "select mob_id, time, lat, lng from mob_gps where mob_id = ? order by time desc limit 30"; return $this->db->getAll($sql, array($mob_id)); } function trans_latlng($val) { $tmp = split('\.', $val, 3); return sprintf("%.8f",$tmp[0] + $tmp[1]/60 + $tmp[2]/3600); } } ?>