<?php
class Connect_mysql
{
/* 成员变量 */
var $info;
var $pdo;
function connect()
{
try {
$this->pdo = new PDO(
"mysql:host=" . $this->info["host"] . ";dbname=" . $this->info["db_name"],
$this->info["db_user"],
$this->info["db_pwd"]
); //创建一个pdo对象
$this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // 设置sql语句查询如果出现问题 就会抛出异常
//set_exception_handler("cus_exception_handler");
} catch (PDOException $e) {
die("connect error:" . $e->getMessage());
}
$this->pdo->exec("set names 'utf8'");
}
function init()
{
$this->info = array(
'host' => 'db',
'db_name' => 'frp',
'db_user' => 'root',
'db_pwd' => 'password',
);
}
function __construct()
{
$this->init();
$this->connect();
}
}