Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
syncEnrollments
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Yeray Santana Hualde
syncEnrollments
Commits
e8561ca9
Commit
e8561ca9
authored
Nov 07, 2011
by
Taylor Otwell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Clean up the MySQL database connector.
parent
05902d22
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
20 deletions
+14
-20
mysql.php
laravel/database/connectors/mysql.php
+14
-20
No files found.
laravel/database/connectors/mysql.php
View file @
e8561ca9
...
@@ -10,38 +10,32 @@ class MySQL extends Connector {
...
@@ -10,38 +10,32 @@ class MySQL extends Connector {
*/
*/
public
function
connect
(
$config
)
public
function
connect
(
$config
)
{
{
$connection
=
new
PDO
(
$this
->
dsn
(
$config
),
$config
[
'username'
],
$config
[
'password'
],
$this
->
options
(
$config
)
);
extract
(
$config
);
if
(
isset
(
$config
[
'charset'
]))
{
$connection
->
prepare
(
"SET NAMES '
{
$config
[
'charset'
]
}
'"
)
->
execute
();
}
return
$connection
;
}
/**
* Format the DSN connection string for a MySQL connection.
*
* @param array $config
* @return string
*/
protected
function
dsn
(
$config
)
{
// Format the initial MySQL PDO connection string. These options are required
// Format the initial MySQL PDO connection string. These options are required
// for every MySQL connection that is established. The connection strings
// for every MySQL connection that is established. The connection strings
// have the following convention: "mysql:host=hostname;dbname=database"
// have the following convention: "mysql:host=hostname;dbname=database"
$dsn
=
sprintf
(
'%s:host=%s;dbname=%s'
,
$
config
[
'driver'
],
$config
[
'host'
],
$config
[
'database'
]
);
$dsn
=
sprintf
(
'%s:host=%s;dbname=%s'
,
$
driver
,
$host
,
$database
);
// Check for any optional MySQL PDO options. These options are not required
// Check for any optional MySQL PDO options. These options are not required
// to establish a PDO connection; however, may be needed in certain server
// to establish a PDO connection; however, may be needed in certain server
// or hosting environments used by the developer.
// or hosting environments used by the developer.
foreach
(
array
(
'port'
,
'unix_socket'
)
as
$key
=>
$value
)
foreach
(
array
(
'port'
,
'unix_socket'
)
as
$key
=>
$value
)
{
{
if
(
isset
(
$config
[
$key
]))
$dsn
.=
";
{
$key
}
=
{
$value
}
"
;
if
(
isset
(
$config
[
$key
]))
{
$dsn
.=
";
{
$key
}
=
{
$value
}
"
;
}
}
$connection
=
new
PDO
(
$dsn
,
$username
,
$password
,
$this
->
options
(
$config
));
if
(
isset
(
$config
[
'charset'
]))
{
$connection
->
prepare
(
"SET NAMES '
{
$charset
}
'"
)
->
execute
();
}
}
return
$
ds
n
;
return
$
connectio
n
;
}
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment