Advertisement
Guest User

Untitled

a guest
May 2nd, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. <?php
  2.  
  3. define('DB_SERVER', 'localhost');
  4. define('DB_USERNAME', 'username');
  5. define('DB_PASSWORD', 'password');
  6. define('DB_DATABASE', 'databasename');
  7.  
  8.  
  9. function getDB()
  10. {
  11. $dbhost=DB_SERVER;
  12. $dbuser=DB_USERNAME;
  13. $dbpass=DB_PASSWORD;
  14. $dbname=DB_DATABASE;
  15. try {
  16. $dbConnection = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
  17. $dbConnection->exec("set names utf8");
  18. $dbConnection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  19. return $dbConnection;
  20. }
  21. catch (PDOException $e) {
  22. echo 'Connection failed: ' . $e->getMessage();
  23. }
  24.  
  25. }
  26.  
  27. $db = getDB();
  28. $stmt = $db->prepare("SELECT nome_banco FROM bancos");
  29. $stmt->execute();
  30. $data = $stmt->fetch(PDO::FETCH_OBJ);
  31. $retorno = implode(',', $data);
  32. echo $retorno;
  33. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement