Hamza Huq
0
Q:

php pdo sql example


<?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();
}

?>
 
0
<?php

$dsn = "mysql:host=localhost;dbname=mydb";
$user = "user12";
$passwd = "12user";

$pdo = new PDO($dsn, $user, $passwd);

0

New to Communities?

Join the community