Answers for "pdo php"

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
8

php pdo connection

$host     = "localhost";//Ip of database, in this case my host machine    
$user     = "root";	//Username to use
$pass     = "qwerty";//Password for that user
$dbname   = "DB";//Name of the database

try {
    $connection = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);
    $connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

}catch(PDOException $e)
{
  echo $e->getMessage();                         
}
Posted by: Guest on April-14-2020
1

pdo connexion

public static function connexionBDD()
    {
        $base = null;

        try {
            $base = new PDO('mysql:host=' . MYSQL_HOSTNAME . '; dbname=' . MYSQL_DATABASE . '', MYSQL_USERNAME, MYSQL_PASSWORD);
        } catch (exception $e) {
            die('Erreur ' . $e->getMessage());
        }

        return $base;
    }
Posted by: Guest on April-02-2020
0

php query pdo

<?php
$sql =  'SELECT name, color, calories FROM fruit ORDER BY name';
foreach  ($conn->query($sql) as $row) {
    print $row['name'] . "\t";
    print  $row['color'] . "\t";
    print $row['calories'] . "\n";
}
?>
Posted by: Guest on April-15-2020
0

pdo example

<?php

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

$pdo = new PDO($dsn, $user, $passwd);
Posted by: Guest on September-09-2020

Browse Popular Code Answers by Language