Advertisement
bielakamil

Łączenie z bazą

Dec 7th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.89 KB | None | 0 0
  1. <?php
  2.  
  3. $host = 'localhost';
  4. $user = 'root';
  5. $password = '';
  6. $database = 'dane_osobowe';
  7.  
  8. // MYSQL
  9.  
  10. $mysql = mysql_connect($host,$user,$password);
  11.  
  12. if (!$mysql) {
  13.     die('Nie udało się połączyć z bazą danych: ' . mysql_error());
  14. }
  15. echo 'Połączenie udane';
  16. mysql_select_db($database);
  17.  
  18.  
  19. //MYSQLI
  20.  
  21. $mysql = mysqli_connect ($host,$user,$password,$database);
  22.  
  23. if (!$mysql) {
  24.     die ('Nie udało się połączyć z bazą danych: ' . mysqli_connect_error());
  25. }
  26.  
  27.  
  28. $mysql = new mysqli ($host,$user,$pasword,$database);
  29.  
  30. if (mysqli_connect_errno())
  31.         {
  32.             header ("Location: mysql-no-connect.php");
  33.         }
  34.  
  35. // PDO
  36.  
  37. try
  38. {
  39.     $pdo = new PDO('mysql:host='.$mysql.';dbname='.$database.';port='.$port, $user, $password );
  40. }
  41.  
  42. catch(PDOException $e)
  43. {
  44.     echo 'Połączenie nie mogło zostać utworzone.';
  45. }        
  46.  
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement