【Laravel3.0.0源码阅读分析】Postgres连接类
作者:互联网
<?php namespace Laravel\Database\Connectors; use PDO;
class Postgres extends Connector {
/**
* Establish a PDO database connection.
* 建立 PDO 数据库连接。
* @param array $config
* @return PDO
*/
public function connect($config)
{
extract($config);
$dsn = "pgsql:host={$host};dbname={$database}";
// The developer has the freedom of specifying a port for the PostgresSQL
// database or the default port (5432) will be used by PDO to create the
// connection to the database for the developer.
// 开发人员可以自由地为 PostgresSQL 数据库指定端口,或者默认端口 (5432) 将被 PDO 用于为开发人员创建到数据库的连接。
if (isset($config['port']))
{
$dsn .= ";port={$config['port']}";
}
$connection = new PDO($dsn, $username, $password, $this->options($config));
// If a character set has been specified, we'll execute a query against
// the database to set the correct character set. By default, this is
// set to UTF-8 which should be fine for most scenarios.
// 如果已指定字符集,我们将对数据库执行查询以设置正确的字符集。 默认情况下,它被设置为 UTF-8,这对于大多数情况应该没问题。
if (isset($config['charset']))
{
$connection->prepare("SET NAMES '{$config['charset']}'")->execute();
}
return $connection;
}
}
github地址: https://github.com/liu-shilong/laravel3-scr
标签:execute,set,UTF,Postgres,charset,character,Laravel3.0,源码,config 来源: https://blog.51cto.com/u_14097531/2972962