×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: user7784c
Added: May 22, 2017 6:25 PM
Views: 6
Tags: connection pdo
Conexión a base de datos de MySql mediante PDO.
  1.     <?php
  2.      
  3.     $servername = "site_host_name";
  4.     $db_username = "site_username";
  5.     $db_password = "password";
  6.     $db_name = "database_name";
  7.      
  8.     try {
  9.         $db = new PDO("mysql:host={$servername};dbname={$db_name}", $db_username, $db_password);
  10.         $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  11.     } catch (PDOException $e) {
  12.         echo "Connection error: " . $e->getMessage();
  13.     }
  14.     ?>
  15.