Answers for "how to define database mysql connection alone and call it in php pdo and define it again"

PHP
2

how to connect pdo php database

<?php
$servername = "localhost";
$username = "username";
$password = "password";

try {
  $conn = new PDO("mysql:host=$servername;dbname=myDB", $username, $password);
  // set the PDO error mode to exception
  $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  echo "Connected successfully";
} catch(PDOException $e) {
  echo "Connection failed: " . $e->getMessage();
}
?>
Posted by: Guest on May-14-2020

Code answers related to "how to define database mysql connection alone and call it in php pdo and define it again"

Browse Popular Code Answers by Language