daily pastebin goal
20%
SHARE
TWEET

Untitled

a guest Jun 30th, 2018 74 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. if (!isset($_POST['search_term'])) {
  3.   die();
  4. }
  5.  
  6. $servername = "127.0.0.1"; // データベース稼働ホストのホスト名
  7. $username = "shizutaro";   // データベースのアクセス権を持つユーザ名
  8. $password = "at_ad437";   // 上記ユーザのパスワード
  9. $dbname = "CSexp1DB";
  10. $dsn = "mysql:dbname=" . $dbname . ";host=" . $servername;
  11.  
  12. try {
  13.   $dbh = new PDO($dsn, $username, $password);
  14. } catch (PDOException $e) {
  15.   echo 'Connexion failed : ' . $e->getMessage();
  16. }
  17.  
  18. $keyword = '%'.$_POST['search_term'].'%';
  19. $sql = "select concat(addr1,addr2,addr3) from zipJapan where concat(addr1,addr2,addr3) like :arg limit 10";
  20.  
  21. $stmt = $dbh->prepare($sql);
  22. $stmt->bindParam(':arg', $keyword);
  23. $stmt->execute();
  24. $data = array();
  25. $data = $stmt->fetchAll(PDO::FETCH_COLUMN);
  26. header("Content-Type: application/json; charset=utf-8");
  27. echo json_encode($data);
  28. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top