Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Defines database connection information
- $settings = [
- 'host' => '127.0.0.1',
- 'name' => 'c9',
- 'port' => '3306',
- 'charset' => 'utf8',
- 'username' => 'admin',
- 'password' => 'root'
- ];
- ?>
- <?php
- // Includes database connection information
- require_once('../settings.php');
- // Establishes connection to database server
- try {
- $dbh = new PDO(
- sprintf(
- 'mysql:host=%s;dbname=%s;port=%s;charset=%s',
- $settings['host'],
- $settings['name'],
- $settings['port'],
- $settings['charset']
- ),
- $settings['username'],
- $settings['password']
- );
- // Prevents emulated prepare statements and sets error mode
- // to PDO::ERRMODE_EXCEPTION
- $dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
- $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- }
- // Prints out errors raised by PDO
- catch (PDOException $e) {
- die('Error: ' . $e->getMessage());
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement