Error message here!

Hide Error message here!

忘记密码?

Error message here!

请输入正确邮箱

Hide Error message here!

密码丢失?请输入您的电子邮件地址。您将收到一个重设密码链接。

Error message here!

返回登录

Close

[reading and analysis of laravel3.0.0 source code] Postgres connection class

wx5bffdbaf11b62 2021-07-26 11:17:57 阅读数:13 评论数:0 点赞数:0 收藏数:0

<?php namespace Laravel\Database\Connectors; use PDO;
class Postgres extends Connector {
/**
* Establish a PDO database connection.
* establish PDO Database connection .
* @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.
// Developers are free to PostgresSQL Database specified port , Or the default port (5432) Will be PDO Used to create a connection to the database for developers .
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.
// If a character set has been specified , We will perform a query on the database to set the correct character set . By default , It is set to UTF-8, This should be OK for most cases .
if (isset($config['charset']))
{
$connection->prepare("SET NAMES '{$config['charset']}'")->execute();
}
return $connection;
}
}

github Address : https://github.com/liu-shilong/laravel3-scr   

Copyright statement
In this paper,the author:[wx5bffdbaf11b62],Reprint please bring the original link, thank you

编程之旅,人生之路,不止于编程,还有诗和远方。
阅代码原理,看框架知识,学企业实践;
赏诗词,读日记,踏人生之路,观世界之行;