Exemple #1
0
 public function run()
 {
     $dsn = $this->dbtype . ':host=' . $this->host . ';' . 'dbname=' . $this->db . ';' . 'charset=' . $this->charset . ';' . 'port=' . $this->port;
     try {
         self::$_pdo = new PDO($dsn, $this->user, $this->password, array(PDO::ATTR_PERSISTENT => true));
         //echo 'success<br>';
     } catch (Exception $e) {
         die('message:' . $e->getMessage());
     }
     self::$_pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
 }
Exemple #2
0
<?php

require 'pdo.php';
$pdos = new pdos();
$pdos->dbtype = 'mysql';
$pdos->host = '127.0.0.1';
$pdos->db = 'test';
$pdos->user = '******';
$pdos->password = '';
$pdos->charset = 'utf8';
$pdos->port = '3306';
$pdos->run();