Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- if (!isset($_POST['search_term'])) {
- die();
- }
- $servername = "127.0.0.1"; // データベース稼働ホストのホスト名
- $username = "shizutaro"; // データベースのアクセス権を持つユーザ名
- $password = "at_ad437"; // 上記ユーザのパスワード
- $dbname = "CSexp1DB";
- $dsn = "mysql:dbname=" . $dbname . ";host=" . $servername;
- try {
- $dbh = new PDO($dsn, $username, $password);
- } catch (PDOException $e) {
- echo 'Connexion failed : ' . $e->getMessage();
- }
- $keyword = '%'.$_POST['search_term'].'%';
- $sql = "select concat(addr1,addr2,addr3) from zipJapan where concat(addr1,addr2,addr3) like :arg limit 10";
- $stmt = $dbh->prepare($sql);
- $stmt->bindParam(':arg', $keyword);
- $stmt->execute();
- $data = array();
- $data = $stmt->fetchAll(PDO::FETCH_COLUMN);
- header("Content-Type: application/json; charset=utf-8");
- echo json_encode($data);
- ?>
Add Comment
Please, Sign In to add comment