public static function getDbc() { if (!self::$dbc) { self::$dbc = new PDO("mysql: host=" . APP_DB_HOST . "; dbname=" . APP_DB_NAME, APP_DB_USER, APP_DB_PASSWORD, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'")); } return self::$dbc; }
/** * Connect to the DB * * This method should be called at the beginning of any function that needs to communicate with the database */ protected static function dbConnect() { if (!self::$dbc) { $dbc = new PDO('mysql:host=127.0.0.1;dbname=codeup_test_db', 'vagrant', 'vagrant'); self::$dbc = $dbc; } }
private static function dbConnect() { if (!self::$dbc) { self::$dbc = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USER, DB_PASS); self::$dbc->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } }
/** * Connect to the DB * * This method should be called at the beginning of any function that needs to communicate with the database */ protected static function dbConnect() { if (!self::$dbc) { self::$dbc = new PDO('mysql:host=127.0.0.1;dbname=codeup_test_db', 'codeup', 'codeup'); self::$dbc->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } }
protected static function dbConnect() { if (!self::$dbc) { self::$dbc = new PDO('mysql:host=' . $_ENV['DB_HOST'] . ';dbname=' . $_ENV['DB_NAME'], $_ENV['DB_USER'], $_ENV['DB_PASS']); self::$dbc->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } }
/** * Connect to the DB * * This method should be called at the beginning of any function that needs to communicate with the database */ protected static function dbConnect() { if (!self::$dbc) { self::$dbc = new PDO('mysql:host=localhost;dbname=codeup_test_db', 'codeup_test_user', 'password'); self::$dbc->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } }
protected static function dbConnect() { if (!self::$dbc) { require __DIR__ . '/../database/db_connect.php'; self::$dbc = $dbc; } }
private static function dbConnect() { if (!self::$dbc) { require 'db_connect.php'; self::$dbc = $dbc; } }
public static function dbConnect() { if (!self::$dbc) { require '../db/db_connect.php'; self::$dbc = $dbc; } }
protected static function dbConnect() { if (!self::$dbc) { self::$dbc = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USER, DB_PASS); // Tell PDO to throw exceptions on error self::$dbc->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } }
protected static function dbConnect() { if (!self::$dbc) { // @TODO: Connect to database require "../database/dbconnect.php"; self::$dbc = $dbc; } }
private static function dbConnect() { if (!self::$dbc) { require_once 'Model_login.php'; require_once 'dbconnect.php'; self::$dbc = $dbc; } }
/** * Connect to the DB * * This method should be called at the beginning of any function that needs to communicate with the database */ protected static function dbConnect() { if (!self::$dbc) { // @TODO: Connect to database self::$dbc = new PDO('mysql:host=' . DB_host . ';dbname=' . DB_name, DB_user, DB_password); self::$dbc->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } }
private static function dbConnect() { if (!self::$dbc) { // @TODO: Connect to database require "db_connect.php"; self::$dbc = $dbc; } }
/** * Connect to the DB * * This method should be called at the beginning of any function that needs to communicate with the database */ protected static function dbConnect() { if (!self::$dbc) { $dbc = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USER, PASSWORD); self::$dbc = $dbc; // @TODO: Connect to database } }
private static function dbConnect() { // If the static property $dbc has not been set, then assign it. if (!self::$dbc) { self::$dbc = new PDO('mysql:host=' . DB_HOST . '; dbname=' . DB_NAME, DB_USER, DB_PASS); // Tell PDO to throw exceptions on error self::$dbc->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } }
/** * Connect to the DB * * This method should be called at the beginning of any function that needs to communicate with the database */ protected static function dbConnect() { if (!self::$dbc) { $servername = "localhost"; $dbname = "parks_db"; $username = "******"; $password = "******"; self::$dbc = new PDO("mysql:host={$servername};dbname={$dbname}", $username, $password); self::$dbc->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } }
/** * Connect to the DB * * This method should be called at the beginning of any function that needs to communicate with the database */ protected static function dbConnect() { if (!self::$dbc) { // Connect to database $dbc = new PDO('mysql:host=127.0.0.1;dbname=users_db', 'admin_user', 'x'); self::$dbc = $dbc; self::$table = 'users'; // Throw exception on PDO error self::$dbc->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } }
protected static function dbConnect() { /* if not already connected, go to next line & connect; singleton pattern - only want one instance of db connection if changed to static would allow override which we don't want could paste contents of configUser_db.php here instead of requiring once at top*/ if (!self::$dbc) { /* @TODO: Connect to database: user_db; name codeup; password codeup*/ self::$dbc = new PDO('mysql:host=' . $_ENV['DB_HOST'] . ';dbname=' . $_ENV['DB_NAME'], $_ENV['DB_USER'], $_ENV['DB_PASS']); // Make sure that instance will use exceptions rather than failing silently. self::$dbc->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } }
private static function dbConnect() { if (!self::$dbc) { self::$dbc = (require 'db_connect.php'); } }
protected static function dbConnect() { if (!self::$dbc) { self::$dbc = (require '../database/db.connect.php'); } }