Search
 
SCRIPT & CODE EXAMPLE
 

PHP

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

PDO connect

<?php
$db = new PDO('mysql:host=myhost;dbname=mydb', 'login', 'password');


Comment

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

pdo connection

<?php
$servername = "localhost";
$username = "root";
$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();
}
?>
Comment

pdo connection

//In this PHP DATA OBJECT (PDO) CONNECTION I am gonna use 
//the exception code that will help hide your database login 
//details from your users if there is an exception (error).
 //dbname(database name)
 //charset(characters encoding )

  try {
    $pdo = new PDO('mysql:host=localhost;dbname=joke;charset=utf8','username','password');
    $pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
  echo 'Successfully Connected to the database';
  } catch (PDOException $e) {
    echo 'ErrorException'.$e->getMessage().'in'.$e->getFile().$e->getCode().$e->getLine();
  } 
Comment

database connection in pdo php

$connect = new PDO("mysql:host=$host;dbname=$db", $user, $pass, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
Comment

connect pdo

$host = '127.0.0.1';
$db   = 'test';
$user = 'root';
$pass = '';
$charset = 'utf8mb4';

$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
$options = [
    PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION,
    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
    PDO::ATTR_EMULATE_PREPARES   => false,
];
try {
     $pdo = new PDO($dsn, $user, $pass, $options);
} catch (PDOException $e) {
     throw new PDOException($e->getMessage(), (int)$e->getCode());
}
Comment

PREVIOUS NEXT
Code Example
Php :: url segment laravel 
Php :: do artisan laravel in code 
Php :: - in php 
Php :: add object in array php 
Php :: Undefined constant "STDOUT" in php 
Php :: laravel observer get old value 
Php :: laravel chunk 
Php :: php add new item to associative array 
Php :: jquery send form data to php 
Php :: Multiple image upload with CodeIgniter 
Php :: tinker faker 
Php :: find value in array php 
Php :: imagick php 
Php :: woocommerce return to shop custom url 
Php :: drupal get node id from twig 
Php :: read pdf text php 
Php :: html in php 
Php :: Image not found or type unknown in pdf 
Php :: get php ini config from terminal 
Php :: php xml to json 
Php :: mp3 file upload code in php 
Php :: laravel packages 
Php :: remove all items of an array except the last 5 in php 
Php :: woocommerce update_status 
Php :: Main features of php 
Php :: spaceship operator 
Php :: SQLSTATE[42S02] lumen 
Php :: laravel eloquent get all where in 
Php :: woocommerce disable links on specific product 
Php :: laravel PageController.php 
ADD CONTENT
Topic
Content
Source link
Name
3+1 =