Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
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
PSDI Army
yii2
Commits
3349af1a
Commit
3349af1a
authored
Apr 10, 2014
by
Qiang Xue
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #3049 from resurtm/db-connection-odbc
Add ODBC support to yii\db\Connection
parents
629ed629
1991c4cb
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
8 deletions
+42
-8
database-basics.md
docs/guide/database-basics.md
+14
-0
CHANGELOG.md
framework/CHANGELOG.md
+1
-0
Connection.php
framework/db/Connection.php
+27
-8
No files found.
docs/guide/database-basics.md
View file @
3349af1a
...
@@ -44,6 +44,20 @@ return [
...
@@ -44,6 +44,20 @@ return [
];
];
```
```
There is a peculiarity when you want to work with the database through the
`ODBC`
layer. When using
`ODBC`
,
connection
`DSN`
doesn't indicate uniquely what database type is being used. That's why you have to override
`driverName`
property of
[
[yii\db\Connection
]
] class to disambiguate that:
```
php
'db'
=>
[
'class'
=>
'yii\db\Connection'
,
'driverName'
=>
'mysql'
,
'dsn'
=>
'odbc:Driver={MySQL};Server=localhost;Database=test'
,
'username'
=>
'root'
,
'password'
=>
''
,
],
```
Please refer to the
[
PHP manual
](
http://www.php.net/manual/en/function.PDO-construct.php
)
for more details
Please refer to the
[
PHP manual
](
http://www.php.net/manual/en/function.PDO-construct.php
)
for more details
on the format of the DSN string.
on the format of the DSN string.
...
...
framework/CHANGELOG.md
View file @
3349af1a
...
@@ -190,6 +190,7 @@ Yii Framework 2 Change Log
...
@@ -190,6 +190,7 @@ Yii Framework 2 Change Log
-
Enh: Improved action filter and action execution flow by supporting installing action filters at controller, module and application levels (qiangxue)
-
Enh: Improved action filter and action execution flow by supporting installing action filters at controller, module and application levels (qiangxue)
-
Enh: Added
`isAssociative()`
and
`isIndexed()`
to
`yii\helpers\ArrayHelper`
(qiangxue)
-
Enh: Added
`isAssociative()`
and
`isIndexed()`
to
`yii\helpers\ArrayHelper`
(qiangxue)
-
Enh: Added
`addSelect`
to
`yii\db\Query`
(Alex-Code)
-
Enh: Added
`addSelect`
to
`yii\db\Query`
(Alex-Code)
-
Enh: Added ODBC support in
`yii\db\Connection`
(nineinchnick, resurtm)
-
Chg #47: Changed Markdown library to cebe/markdown and adjusted Markdown helper API (cebe)
-
Chg #47: Changed Markdown library to cebe/markdown and adjusted Markdown helper API (cebe)
-
Chg #735: Added back
`ActiveField::hiddenInput()`
(qiangxue)
-
Chg #735: Added back
`ActiveField::hiddenInput()`
(qiangxue)
-
Chg #1186: Changed
`Sort`
to use comma to separate multiple sort fields and use negative sign to indicate descending sort (qiangxue)
-
Chg #1186: Changed
`Sort`
to use comma to separate multiple sort fields and use negative sign to indicate descending sort (qiangxue)
...
...
framework/db/Connection.php
View file @
3349af1a
...
@@ -89,7 +89,8 @@ use yii\caching\Cache;
...
@@ -89,7 +89,8 @@ use yii\caching\Cache;
* ]
* ]
* ~~~
* ~~~
*
*
* @property string $driverName Name of the DB driver. This property is read-only.
* @property string $driverName Name of the DB driver. Change this property if you want to override the
* driver name specified in [[dsn]]. This can be useful if you're working with the database via ODBC layer.
* @property boolean $isActive Whether the DB connection is established. This property is read-only.
* @property boolean $isActive Whether the DB connection is established. This property is read-only.
* @property string $lastInsertID The row ID of the last row inserted, or the last value retrieved from the
* @property string $lastInsertID The row ID of the last row inserted, or the last value retrieved from the
* sequence object. This property is read-only.
* sequence object. This property is read-only.
...
@@ -261,6 +262,10 @@ class Connection extends Component
...
@@ -261,6 +262,10 @@ class Connection extends Component
* @var Schema the database schema
* @var Schema the database schema
*/
*/
private
$_schema
;
private
$_schema
;
/**
* @var string driver name
*/
private
$_driverName
;
/**
/**
* Returns a value indicating whether the DB connection is established.
* Returns a value indicating whether the DB connection is established.
...
@@ -348,11 +353,13 @@ class Connection extends Component
...
@@ -348,11 +353,13 @@ class Connection extends Component
$pdoClass
=
$this
->
pdoClass
;
$pdoClass
=
$this
->
pdoClass
;
if
(
$pdoClass
===
null
)
{
if
(
$pdoClass
===
null
)
{
$pdoClass
=
'PDO'
;
$pdoClass
=
'PDO'
;
if
((
$pos
=
strpos
(
$this
->
dsn
,
':'
))
!==
false
)
{
if
(
$this
->
_driverName
!==
null
)
{
$driver
=
$this
->
_driverName
;
}
elseif
((
$pos
=
strpos
(
$this
->
dsn
,
':'
))
!==
false
)
{
$driver
=
strtolower
(
substr
(
$this
->
dsn
,
0
,
$pos
));
$driver
=
strtolower
(
substr
(
$this
->
dsn
,
0
,
$pos
));
if
(
$driver
===
'mssql'
||
$driver
===
'dblib'
||
$driver
===
'sqlsrv'
)
{
$pdoClass
=
'yii\db\mssql\PDO'
;
}
}
if
(
isset
(
$driver
)
&&
(
$driver
===
'mssql'
||
$driver
===
'dblib'
||
$driver
===
'sqlsrv'
))
{
$pdoClass
=
'yii\db\mssql\PDO'
;
}
}
}
}
...
@@ -533,17 +540,29 @@ class Connection extends Component
...
@@ -533,17 +540,29 @@ class Connection extends Component
}
}
/**
/**
* Returns the name of the DB driver for the current [[dsn]].
* Returns the name of the DB driver. Based on the the current [[dsn]], in case it was not set explicitly
* by an end user.
* @return string name of the DB driver
* @return string name of the DB driver
*/
*/
public
function
getDriverName
()
public
function
getDriverName
()
{
{
if
(
$this
->
_driverName
===
null
)
{
if
((
$pos
=
strpos
(
$this
->
dsn
,
':'
))
!==
false
)
{
if
((
$pos
=
strpos
(
$this
->
dsn
,
':'
))
!==
false
)
{
return
strtolower
(
substr
(
$this
->
dsn
,
0
,
$pos
));
$this
->
_driverName
=
strtolower
(
substr
(
$this
->
dsn
,
0
,
$pos
));
}
else
{
}
else
{
$this
->
open
();
$this
->
open
();
$this
->
_driverName
=
strtolower
(
$this
->
pdo
->
getAttribute
(
PDO
::
ATTR_DRIVER_NAME
));
return
strtolower
(
$this
->
pdo
->
getAttribute
(
PDO
::
ATTR_DRIVER_NAME
));
}
}
}
}
return
$this
->
_driverName
;
}
/**
* Changes the current driver name.
* @param string $driverName name of the DB driver
*/
public
function
setDriverName
(
$driverName
)
{
$this
->
_driverName
=
strtolower
(
$driverName
);
}
}
}
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