<?PHP/*phone numbers differentiate addresses. Store to database;*/classfilter{Private $_phone= ' '; Private $_api= ' http://mobsec-dianhua.baidu.com/dianhua_api/open/location?tel= '; Private $_user; Private $_host; Private $_pwd; Private $_dbname; Private Static $conn=NULL; Private function__construct () {} Public Static function_interance () {//Returning Instances if(Self::$conn==NULL)returnSelf::$conn=NewFilter; } /*param host param user param pwd param dbname return null*/ Public function_conn ($host,$user,$pwd,$dbname) { $this->_host =$host; $this->_user =$user; $this->_pwd =$pwd; $this->_dbname =$dbname; } Public function_select () {Try { $pdo=NewPDO (' mysql:host= '.$this->_host. ';d bname= '.$this->_dbname,$this->_user,$this-_pwd); $pdo->query ("SET CHARSET ' UTF8 '"); } Catch(pdoexception$e) { die("Connection fail:").$e-GetMessage (); } $sql= "SELECT * FROM Phone WHERE";//SQL statement to be optimized$stmt=$pdo->prepare ($sql); $stmt-execute (); while($result=$stmt->fetch (PDO::Fetch_assoc)) { if($result!= [])return $result; } } /*param phone return null*/ Public function_setdata ($phone) { if($phone!=NULLandstrlen($phone) = = 11) { $this->_phone =$phone; } } /*param phone param API API address return JSON string*/ Public function_rseponsetext () {$ch=Curl_init (); $str=$this->_api.$this-_phone; curl_setopt ($ch, Curlopt_url,$str); curl_setopt ($ch, Curlopt_returntransfer,true); $output= Curl_exec ($ch); return $output; }}
Continuous update ...
PHP number attribution region Automated Query API encapsulation