daily pastebin goal
50%
SHARE
TWEET

Untitled

a guest Jan 25th, 2016 82 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <? php
  2.  
  3. function connectDB() {
  4.     $hostname = 'xxxxxxxx';
  5.     $db = 'xxxxxxx';
  6.     $user = 'xxxxxxxx';
  7.     $pass = 'xxxxxxx';
  8.  
  9.     $dbh = new PDO("mysql:host=$hostname; dbname=$db; charset=utf8", $user, $pass, array(PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
  10.  
  11.     $sql = "//my query";
  12.  
  13.     $query = $dbh->prepare($sql);
  14.     $query->execute(array('//value','//value'));            
  15.     $query->setFetchMode(PDO::FETCH_ASSOC);
  16.  
  17.     while ($r = $query->fetch()):
  18.  
  19.         $var1 = $r['column1'];
  20.         $var2 = $r['column2'];
  21.         $var3 = $r['column3'];
  22.         $var4 = $r['column4'];
  23.         $var5 = $r['column5'];
  24.  
  25.     endwhile;                                                      
  26.  
  27. }
  28.  
  29. ?>
  30.    
  31. <?php
  32. include 'functions.php';
  33.  
  34. ?>
  35.  
  36. <?php
  37.  
  38. try {
  39.  
  40. connectDB();
  41. echo 'You are connected to Database';
  42. echo $var1;
  43. $dbh = null;
  44.  
  45.     }
  46. catch(PDOException $e) {
  47.         echo $e -> getMessage();
  48.     }
  49.  
  50. ?>
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