daily pastebin goal
11%
SHARE
TWEET

Untitled

a guest Jun 29th, 2018 107 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. class Test
  3. {
  4.   // database object
  5.   private $pdo;
  6.  
  7.   public function __construct($servername, $username, $password, $dbname) {
  8.     // open database connection.
  9.     $dsn = "mysql:dbname=" . $dbname . ";host=" . $servername;
  10.     $this->pdo = null;
  11.  
  12.     // create/check connection
  13.     try {
  14.       $this->pdo = new PDO($dsn, $username, $password);
  15.     } catch (PDOException $e) {
  16.       print('Connection failed: ' . $e->getMessage());
  17.       die();
  18.     }
  19.   }
  20.  
  21.   public function __destruct() {
  22.     // close database connection.
  23.     $this->pdo = null;
  24.   }
  25.  
  26.   public function search_address($input,$sql) {
  27.     $stmt = $this->pdo->prepare($sql);
  28.     $stmt->bindParam(':arg', $input);
  29.     $stmt->execute();
  30.     return $stmt->fetchAll();
  31.   }
  32. }
  33.  
  34. $servername = "127.0.0.1"; // データベース稼働ホストのホスト名
  35. $username = "shizutaro";   // データベースのアクセス権を持つユーザ名
  36. $password = "at_ad437";   // 上記ユーザのパスワード
  37. $dbname = "CSexp1DB";//データベース名
  38. $input_arg = 2;
  39. $sql ="select * from table name where id = :arg";
  40. $postal = new Test($servername, $username, $password, $dbname);
  41. $result = $postal->search_address($input_arg, $sql);
  42. ?>
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