【Laravel3.0.0源码阅读分析】MySQL连接类
2021/7/3 19:24:53
本文主要是介绍【Laravel3.0.0源码阅读分析】MySQL连接类,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
<?php namespace Laravel\Database\Connectors; use PDO; class MySQL extends Connector { /** * Establish a PDO database connection. * 建立 PDO 数据库连接。 * @param array $config * @return PDO */ public function connect($config) { extract($config); $dsn = "mysql:host={$host};dbname={$database}"; // The developer has the freedom of specifying a port for the MySQL database // or the default port (3306) will be used to make the connection by PDO. // The Unix socket may also be specified if necessary. // 开发者可以自由指定 MySQL 数据库的端口,或者默认端口(3306)将用于通过 PDO 进行连接。如果需要,也可以指定 Unix 套接字。 if (isset($config['port'])) { $dsn .= ";port={$config['port']}"; } if (isset($config['unix_socket'])) { $dsn .= ";unix_socket={$config['unix_socket']}"; } $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
这篇关于【Laravel3.0.0源码阅读分析】MySQL连接类的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-06-25MySQL报错Duplicate entry '0' for key 'PRIMARY'
- 2024-05-29阿里 Canal 实时同步 MySQL 增量数据至 ClickHouse 数据库
- 2024-05-24在Linux下管理MySQL的大小写敏感性
- 2024-04-26MySQL查出时间比实际晚8小时的解决方案
- 2024-04-01JPA不识别MySQL的枚举类型
- 2024-03-30mysql数据库表卡死解决方法
- 2024-03-15MySQL多数据源笔记5-ShardingJDBC实战
- 2024-03-11natural join mysql
- 2024-03-11关于VS2017,VS2015 中利用 EF使用Mysql 不显示数据源问题解决方案
- 2024-02-26mysql 阿里云xb后缀备份文件恢复-icode9专业技术文章分享