Answers for "databsase connection PDO"

PHP
3

pdo db connection

<?php
$pdo = new PDO('mysql:host=localhost;dbname=databasename', 'username', 'password');
?>
Posted by: Guest on September-23-2020
0

php PDO database connection

$hostName = "localhost";
$dbName = "test";
$userName = "test";
$password = "test1";
try {
    $pdo = new PDO("mysql:host=$hostName;dbname=$dbName",$userName,$password);
    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    echo "Connected successfully"; 
    }
    catch(PDOException $e)
    {
     echo "Connection failed: " . $e->getMessage();
    }
Posted by: Guest on May-17-2021

Browse Popular Code Answers by Language