亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

Connector.php

標簽:
PHP

<?php

 

namespace Illuminate\Database\Connectors;

 

use PDO;

use Exception;

use Illuminate\Support\Arr;

use Illuminate\Database\DetectsLostConnections;

// that was system class

class 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

}

點擊查看更多內容
TA 點贊

若覺得本文不錯,就分享一下吧!

評論

作者其他優質文章

正在加載中
  • 推薦
  • 評論
  • 收藏
  • 共同學習,寫下你的評論
感謝您的支持,我會繼續努力的~
掃碼打賞,你說多少就多少
贊賞金額會直接到老師賬戶
支付方式
打開微信掃一掃,即可進行掃碼打賞哦
今天注冊有機會得

100積分直接送

付費專欄免費學

大額優惠券免費領

立即參與 放棄機會
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號

舉報

0/150
提交
取消