Answers for "return PDO connection php doc"

PHP
6

php mysql pdo connection

<?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 April-10-2020
1

pdo connection php

<?php
$db = "mysql:host=localhost;dbname=pdolearn";
$user = "root";
$password = "";

$pdo = new PDO($db, $user, $password);

// $stmt = "SELECT * FROM countries";   //for mySQL
$stmt = $pdo->query("SELECT * from countries");

// while($row = mysqli_fetch_assoc($stmt))  //for mysql
while ($row = $stmt->fetch())
{
    echo    "<pre>";

    print_r($row);
}
Posted by: Guest on October-04-2021

Browse Popular Code Answers by Language