標籤:lte out new from [] 更新 die elf cti
<?php/* 電話號碼區分地址.儲存到資料庫;*/class Filter{ 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 () { // 返回執行個體 if (self::$conn == null) return self::$conn = new Filter; } /* 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 = new PDO(‘mysql:host=‘ . $this->_host . ‘;dbname=‘ . $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語句 $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 != null and strlen($phone) == 11) { $this->_phone = $phone; } } /* param phone 電話 param api api地址 return json 字串 */ 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; }}
持續更新...
PHP號碼歸屬地區分自動化查詢API封裝