Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

php how to connect to db using PDO

<?php 
  $db_src    = "mysql:host=localhost;dbname=databasename";
  $db_user   = "root";
  $db_pass   = "";
  try{
    $connect = new PDO($db_src, $db_user, $db_pass);
    $connect->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  }
  catch(PDOEXCEPTION $err){
    echo "Failed To Connect. Error " . $err->getMessage();
  }
/* Variable $connect will be used to execute DB Statements*/
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #php #connect #db #PDO
ADD COMMENT
Topic
Name
2+1 =