PHP Classes

File: db.php

Recommend this page to a friend!
  Classes of Channaveer Hakari   PHP PDO CRUD Example   db.php   Download  
File: db.php
Role: Auxiliary script
Content type: text/plain
Description: PDO database object creation script
Class: PHP PDO CRUD Example
Example code to implement CRUD operations with PDO
Author: By
Last change:
Date: 7 months ago
Size: 575 bytes
 

Contents

Class file image Download
<?php
require_once './init.php';

$host = 'localhost';
$db_name = 'pdo_training';
$db_username = 'root';
$db_password = 'root';
$dsn = 'mysql:host='. $host .';dbname='. $db_name;
$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, $db_username, $db_password);
} catch (
PDOException $e) {
    exit(
$e->getMessage());
}