Search code snippets, questions, articles...

Connect to DB using PDO


class Dbn {
    private $host = 'localhost';
    private $user = 'root';
    private $pass = '';
    private $dbName = 'DLcleaners';

    protected function connect() {
        $dsn = 'mysql:host=' . $this->host . ';dbname=' . $this->dbName;
        $pdo = new PDO($dsn, $this->user, $this->pass);
        $pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
        return $pdo;

PDO connect 

Search Index Data (The code snippet can also be found with below search text)

PDO connect to DB
Was this helpful?
Programming Feeds
Learn something new everyday on Devsheet