×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Maniruzzaman Akash
Added: Aug 19, 2016 8:42 PM
Modified: Aug 19, 2016 8:43 PM
Views: 23
Connection with the mysql database using 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. ?>