Advertisement
Guest User

Untitled

a guest
Apr 4th, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.50 KB | None | 0 0
  1. <?php
  2. $link = mysqli_connect("127.0.0.1", "user", "password", "database");
  3.  
  4. if (!$link) {
  5. echo "Error: Unable to connect to MySQL.";
  6. exit;
  7. }
  8.  
  9. echo "Success: Connection to MySQL ready.";
  10. mysqli_close($link);
  11. ?>
  12.  
  13. <?php
  14. /* Connect to a MySQL database using driver invocation */
  15. $dsn = 'mysql:dbname=testdb;host=127.0.0.1';
  16. $user = 'dbuser';
  17. $password = 'dbpass';
  18.  
  19. try {
  20. $dbh = new PDO($dsn, $user, $password);
  21. } catch (PDOException $e) {
  22. echo 'Connection failed: ' . $e->getMessage();
  23. }
  24.  
  25. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement