Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <!--
- To change this license header, choose License Headers in Project Properties.
- To change this template file, choose Tools | Templates
- and open the template in the editor.
- -->
- <html>
- <head>
- <meta charset="UTF-8">
- <title>PHP PDO 2</title>
- </head>
- <body>
- <h1>Acceso a datos con PDO desde PHP</h1>
- <?php
- // PASO 1: Conexion a la base de datos con control de errores
- try{
- echo 'Conectando con la base de datos ...';
- // Crear objeto de conexion a la base de datos
- $dsn = "mysql:host=localhost;dbname=world;charset=utf8";
- $username = "root";
- $password = "Temp2016$$";
- $db = new PDO($dsn, $username, $password);
- $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, FALSE);
- echo 'Conexion establecida.';
- } catch (PDOException $e) {
- echo 'Error de conexion a la base de datos.'.PHP_EOL;
- echo $e->getMessage();
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement