PHP number attribution region Automated Query API encapsulation

Source: Internet
Author: User

<?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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.