Advertisement
Guest User

Untitled

a guest
Apr 8th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Ligação ao mysql</title>
  5. </head>
  6. <body>
  7. <?php
  8. $url = "localhost";
  9. $username = "root";
  10. $password = "eminem";
  11. $database = "phpfirst";
  12.  
  13. // Create connection
  14. $conn = new mysqli($url, $username, $password, $database);
  15.  
  16. // Check connection
  17. if ($conn->connect_error) {
  18. //esta merda para o php (nao faz mais nada deste ficheiro) e da a mensagem de erro que deu no mysql
  19. die("Connection failed: " . $conn->connect_error);
  20. }
  21. echo "Connected successfully";
  22.  
  23. $sql="insert into teste values (1, 'ana');";
  24.  
  25. if($conn -> query($sql) == true){
  26. echo "registo adicionado com sucesso";
  27. }else{
  28. echo "erro no insert: " . $conn->error;
  29. }
  30. ?>
  31. </body>
  32. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement