Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
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
Tomáš Trávníček
doctrine-dbal
Commits
a8f66a29
Commit
a8f66a29
authored
Jan 04, 2015
by
Steve Müller
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #755 from gohanman/mysqli-pdo-fetch-obj
Update MysqliStatement to support PDO::FETCH_OBJ Close #755
parents
b17992b5
57379036
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
0 deletions
+47
-0
MysqliStatement.php
lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php
+10
-0
DataAccessTest.php
tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php
+37
-0
No files found.
lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php
View file @
a8f66a29
...
...
@@ -264,6 +264,16 @@ class MysqliStatement implements \IteratorAggregate, Statement
return
$ret
;
case
PDO
::
FETCH_OBJ
:
$assoc
=
array_combine
(
$this
->
_columnNames
,
$values
);
$ret
=
new
\stdClass
();
foreach
(
$assoc
as
$column
=>
$value
)
{
$ret
->
$column
=
$value
;
}
return
$ret
;
default
:
throw
new
MysqliException
(
"Unknown fetch type '
{
$fetchMode
}
'"
);
}
...
...
tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php
View file @
a8f66a29
...
...
@@ -641,6 +641,43 @@ class DataAccessTest extends \Doctrine\Tests\DbalFunctionalTestCase
$this
->
assertEquals
(
0
,
count
(
array_filter
(
$row
,
function
(
$v
)
{
return
!
is_numeric
(
$v
);
})),
"should be no non-numerical elements in the result."
);
}
/**
* @group DBAL-1091
*/
public
function
testFetchAllStyleObject
()
{
$driverName
=
$this
->
_conn
->
getDriver
()
->
getName
();
if
(
in_array
(
$driverName
,
array
(
'oci8'
),
true
))
{
$this
->
markTestSkipped
(
sprintf
(
'Driver "%s" does not support hydrating data to an object.'
,
$driverName
));
}
$this
->
setupFixture
();
$sql
=
'SELECT test_int, test_string, test_datetime FROM fetch_table'
;
$stmt
=
$this
->
_conn
->
prepare
(
$sql
);
$stmt
->
execute
();
$results
=
$stmt
->
fetchAll
(
\PDO
::
FETCH_OBJ
);
$this
->
assertCount
(
1
,
$results
);
$this
->
assertInstanceOf
(
'stdClass'
,
$results
[
0
]);
$this
->
assertEquals
(
1
,
property_exists
(
$results
[
0
],
'test_int'
)
?
$results
[
0
]
->
test_int
:
$results
[
0
]
->
TEST_INT
);
$this
->
assertEquals
(
'foo'
,
property_exists
(
$results
[
0
],
'test_string'
)
?
$results
[
0
]
->
test_string
:
$results
[
0
]
->
TEST_STRING
);
$this
->
assertStringStartsWith
(
'2010-01-01 10:10:10'
,
property_exists
(
$results
[
0
],
'test_datetime'
)
?
$results
[
0
]
->
test_datetime
:
$results
[
0
]
->
TEST_DATETIME
);
}
/**
* @group DBAL-196
*/
...
...
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