Advertisement
Guest User

Untitled

a guest
Dec 19th, 2016
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <!--
  3. To change this license header, choose License Headers in Project Properties.
  4. To change this template file, choose Tools | Templates
  5. and open the template in the editor.
  6. -->
  7. <html>
  8. <head>
  9. <meta charset="UTF-8">
  10. <title>PHP PDO 2</title>
  11. </head>
  12. <body>
  13. <h1>Acceso a datos con PDO desde PHP</h1>
  14. <?php
  15. // PASO 1: Conexion a la base de datos con control de errores
  16.  
  17. try{
  18. echo 'Conectando con la base de datos ...';
  19. // Crear objeto de conexion a la base de datos
  20. $dsn = "mysql:host=localhost;dbname=world;charset=utf8";
  21. $username = "root";
  22. $password = "Temp2016$$";
  23. $db = new PDO($dsn, $username, $password);
  24. $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  25. $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, FALSE);
  26. echo 'Conexion establecida.';
  27. } catch (PDOException $e) {
  28. echo 'Error de conexion a la base de datos.'.PHP_EOL;
  29. echo $e->getMessage();
  30. }
  31.  
  32. ?>
  33. </body>
  34. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement