Answers for "new pdo"

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
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
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
3

pdo db connection

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

PDO connect

<?php
$db = new PDO('mysql:host=myhost;dbname=mydb', 'login', 'password');
Posted by: Guest on August-09-2020
1

connect php to mysql pdo

<?php 
  
	$pdo = new PDO('mysql:host=localhost;
  				dbname=the_name_of_your_databe,
  				'username', 
                'password'');
# by default your username is root 
# if you don't have a password don't fill in it

#(optional) : 
	$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
	$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);

?>
Posted by: Guest on April-25-2020

Browse Popular Code Answers by Language