[李景山php]每天laravel-20161119|Connector.php
来源:互联网 发布:建网站主流软件 编辑:程序博客网 时间:2024/06/08 06:16
<?phpnamespace Illuminate\Database\Connectors;use PDO;use Exception;use Illuminate\Support\Arr;use Illuminate\Database\DetectsLostConnections;// that was system classclass Connector{// a connector use DetectsLostConnections;// a trait like detects lost connections /** * The default PDO connection options. * * @var array */ protected $options = [ PDO::ATTR_CASE => PDO::CASE_NATURAL, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL, PDO::ATTR_STRINGIFY_FETCHES => false, PDO::ATTR_EMULATE_PREPARES => false, ];// set all this pdo options /** * Get the PDO options based on the configuration. * * @param array $config * @return array */ public function getOptions(array $config) { $options = Arr::get($config, 'options', []);// get configs options default is empty array return array_diff_key($this->options, $options) + $options;// set the new option }// get options /** * Create a new PDO connection. * * @param string $dsn * @param array $config * @param array $options * @return \PDO */ public function createConnection($dsn, array $config, array $options) {// create a new pdo connection. $username = Arr::get($config, 'username');//username $password = Arr::get($config, 'password');// password try { $pdo = new PDO($dsn, $username, $password, $options); } catch (Exception $e) {// try connection this function $pdo = $this->tryAgainIfCausedByLostConnection( $e, $dsn, $username, $password, $options// throw exception ); } return $pdo;// if ok,just return this pdo function } /** * Get the default PDO connection options. * * @return array */ public function getDefaultOptions() { return $this->options; }// get the default Options by this class /** * Set the default PDO connection options. * * @param array $options * @return void */ public function setDefaultOptions(array $options) { $this->options = $options; }// can set the default options in this way /** * Handle a exception that occurred during connect execution. * * @param \Exception $e * @param string $dsn * @param string $username * @param string $password * @param array $options * @return \PDO * * @throws \Exception */ protected function tryAgainIfCausedByLostConnection(Exception $e, $dsn, $username, $password, $options) {//Handle a exception that occurred during connect execution if ($this->causedByLostConnection($e)) { return new PDO($dsn, $username, $password, $options); } throw $e; }// throw $e}
0 0
- [李景山php]每天laravel-20161119|Connector.php
- [李景山php]每天laravel-20160922|RedisServicProvider.php
- [李景山php]每天laravel-20160923|Hub.php
- [李景山php]每天laravel-20160924|PiplineServiceProvider.php
- [李景山php]每天laravel-20160925|Pipeline.php
- [李景山php]每天laravel-20160926|DatabasePresenceVerifier.php
- [李景山php]每天laravel-20160927|Factory.php
- [李景山php]每天laravel-20160928|PresenceVerifierInterface.php
- [李景山php]每天laravel-20160929|ValidatesWhenResolved.php
- [李景山php]每天laravel-20160930|ValidationException.php
- [李景山php]每天laravel-20161001|ValidationServiceProvider.php
- [李景山php]每天laravel-20161016|JsonResponse.php
- [李景山php]每天laravel-20161017|ResponseTrait.php
- [李景山php]每天laravel-20161017|UploadedFile.php
- [李景山php]每天laravel-20161023|Reponse.php
- [李景山php]每天laravel-20161024|ArrayLoader.php
- [李景山php]每天laravel-20161025|LoaderInterface.php
- [李景山php]每天laravel-20161026|TranslationServiceProvider.php
- 20.获取网络图片,将图片存储在文件,缓存中,然后先从缓存中读取,没有再从文件中读取
- 机器学习 - 第一讲
- 利用ZooKeeper简单实现分布式锁
- 数组的sizeof
- sap记帐码
- [李景山php]每天laravel-20161119|Connector.php
- java冒泡排序
- 机器学习 - 第二讲
- 向后台请求数据的方式
- java使用rxtx串口通信配置及简单示例
- hdu5889 最短路加网络流
- 玩转【斗鱼直播APP】系列之首页布局分析实现
- 机器学习 - 编程练习(一):线性回归
- Xcode 8新特性和iOS 10开发技术