connect() public method

根据配置文件连接
public connect ( )
Example #1
0
     if (strpos($host, ':') !== FALSE) {
         list($host, $port) = explode(':', $host);
     } else {
         $port = 3306;
     }
     try {
         $link = new PDO("mysql:host={$host};port={$port};", $user, $pass);
     } catch (Exception $e) {
         $error = $e->getMessage();
         message(1, $error);
     }
     $host = $host . ':' . $port;
     $conf['db']['type'] = 'pdo_mysql';
     $conf['db']['pdo_mysql'] = array('master' => array('host' => $host, 'user' => $user, 'password' => $pass, 'name' => $name, 'charset' => 'utf8', 'engine' => 'MyISAM'), 'slaves' => array());
     $db = new db_pdo_mysql($conf['db']['pdo_mysql']);
     $db->connect();
     if ($db->errno == -10000) {
         $db->errno = 0;
         $r = $link->exec("CREATE DATABASE `{$name}`");
         if ($r === FALSE) {
             message(-1, "尝试创建数据库失败:{$name}");
         }
     } elseif ($db->errno != 0) {
         message(-1, $db->errstr);
     }
 } else {
     message(-1, '不支持的 type');
 }
 $r = $db->find_one("SELECT * FROM `bbs_user` LIMIT 1");
 !empty($r) and !$force and message(5, '已经安装过了。');
 !is_dir('./upload/avatar') and mkdir('./upload/avatar', 0777);