Subversion Repository Public Repository

Nextrek

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
<?php namespace Illuminate\Database\Connectors;

class MySqlConnector extends Connector implements ConnectorInterface {

	/**
	 * Establish a database connection.
	 *
	 * @param  array  $config
	 * @return \PDO
	 */
	public function connect(array $config)
	{
		$dsn = $this->getDsn($config);

		$options = $this->getOptions($config);

		// We need to grab the PDO options that should be used while making the brand
		// new connection instance. The PDO options control various aspects of the
		// connection's behavior, and some might be specified by the developers.
		$connection = $this->createConnection($dsn, $config, $options);

		if (isset($config['unix_socket']))
		{
			$connection->exec("use {$config['database']};");
		}

		$collation = $config['collation'];

		// Next we will set the "names" and "collation" on the clients connections so
		// a correct character set will be used by this client. The collation also
		// is set on the server but needs to be set here on this client objects.
		$charset = $config['charset'];

		$names = "set names '$charset'".
			( ! is_null($collation) ? " collate '$collation'" : '');

		$connection->prepare($names)->execute();

		// If the "strict" option has been configured for the connection we'll enable
		// strict mode on all of these tables. This enforces some extra rules when
		// using the MySQL database system and is a quicker way to enforce them.
		if (isset($config['strict']) && $config['strict'])
		{
			$connection->prepare("set session sql_mode='STRICT_ALL_TABLES'")->execute();
		}

		return $connection;
	}

	/**
	 * Create a DSN string from a configuration. Chooses socket or host/port based on
	 * the 'unix_socket' config value
	 *
	 * @param  array   $config
	 * @return string
	 */
	protected function getDsn(array $config)
	{
		return $this->configHasSocket($config) ? $this->getSocketDsn($config) : $this->getHostDsn($config);
	}

	/**
	 * Determine if the given configuration array has a UNIX socket value.
	 *
	 * @param  array  $config
	 * @return bool
	 */
	protected function configHasSocket(array $config)
	{
		return isset($config['unix_socket']) && ! empty($config['unix_socket']);
	}

	/**
	 * Get the DSN string for a socket configuration.
	 *
	 * @param  array  $config
	 * @return string
	 */
	protected function getSocketDsn(array $config)
	{
		extract($config);

		return "mysql:unix_socket={$config['unix_socket']};dbname={$database}";
	}

	/**
	 * Get the DSN string for a host / port configuration.
	 *
	 * @param  array  $config
	 * @return string
	 */
	protected function getHostDsn(array $config)
	{
		extract($config);

		return isset($config['port'])
                        ? "mysql:host={$host};port={$port};dbname={$database}"
                        : "mysql:host={$host};dbname={$database}";
	}

}

Commits for Nextrek/Aiba_backup/vendor/laravel/framework/src/Illuminate/Database/Connectors/MySqlConnector.php

Diff revisions: vs.
Revision Author Commited Message
1464 MOliva picture MOliva Tue 13 Oct, 2020 11:16:56 +0000