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
440bef08
Commit
440bef08
authored
Nov 10, 2006
by
zYne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated Doctrine_Db docs
parent
d8f35ee0
Changes
9
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
112 additions
and
32 deletions
+112
-32
Basic Components - DB - Chaining listeners.php
manual/codes/Basic Components - DB - Chaining listeners.php
+3
-3
Basic Components - DB - Connecting to a database.php
...odes/Basic Components - DB - Connecting to a database.php
+0
-10
Basic Components - DB - Introduction.php
manual/codes/Basic Components - DB - Introduction.php
+0
-0
Basic Components - DB - Using event listeners.php
...l/codes/Basic Components - DB - Using event listeners.php
+5
-5
Basic Components - DB - Chaining listeners.php
manual/docs/Basic Components - DB - Chaining listeners.php
+7
-0
Basic Components - DB - Connecting to a database.php
...docs/Basic Components - DB - Connecting to a database.php
+49
-7
Basic Components - DB - Introduction.php
manual/docs/Basic Components - DB - Introduction.php
+4
-4
Basic Components - DB - Using event listeners.php
...al/docs/Basic Components - DB - Using event listeners.php
+39
-0
documentation.php
manual/documentation.php
+5
-3
No files found.
manual/codes/Basic Components - DB - Chaining listeners.php
View file @
440bef08
...
...
@@ -2,12 +2,12 @@
// using PDO dsn for connecting sqlite memory table
$dbh
=
Doctrine_D
B
::
getConnection
(
'sqlite::memory:'
);
$dbh
=
Doctrine_D
b
::
getConnection
(
'sqlite::memory:'
);
class
Counter
extends
Doctrine_D
B
_EventListener
{
class
Counter
extends
Doctrine_D
b
_EventListener
{
private
$queries
=
0
;
public
function
onQuery
(
Doctrine_D
B
$dbh
,
$query
,
$params
)
{
public
function
onQuery
(
Doctrine_D
b_Event
$event
)
{
$this
->
queries
++
;
}
public
function
count
()
{
...
...
manual/codes/Basic Components - DB - Connecting to a database.php
View file @
440bef08
<?php
// using PDO dsn for connecting sqlite memory table
$dbh
=
Doctrine_DB
::
getConnection
(
'sqlite::memory:'
);
// using PEAR like dsn for connecting mysql database
$dsn
=
'mysql://root:password@localhost/test'
;
$dbh
=
Doctrine_DB
::
getConnection
(
$dsn
);
?>
manual/codes/Basic Components - DB - Introduction.php
0 → 100644
View file @
440bef08
manual/codes/Basic Components - DB - Using event listeners.php
View file @
440bef08
...
...
@@ -2,14 +2,14 @@
// using PDO dsn for connecting sqlite memory table
$dbh
=
Doctrine_D
B
::
getConnection
(
'sqlite::memory:'
);
$dbh
=
Doctrine_D
b
::
getConnection
(
'sqlite::memory:'
);
class
MyLogger
extends
Doctrine_D
B
_EventListener
{
public
function
onPreQuery
(
Doctrine_D
B
$dbh
,
$query
,
$params
)
{
class
MyLogger
extends
Doctrine_D
b
_EventListener
{
public
function
onPreQuery
(
Doctrine_D
b_Event
$event
)
{
print
"database is going to be queried!"
;
}
public
function
onQuery
(
Doctrine_D
B
$dbh
,
$query
,
$params
)
{
print
"executed:
$query
"
;
public
function
onQuery
(
Doctrine_D
b_Event
$event
)
{
print
"executed:
"
.
$event
->
getQuery
()
;
}
}
...
...
manual/docs/Basic Components - DB - Chaining listeners.php
0 → 100644
View file @
440bef08
Doctrine_Db
supports
event
listener
chaining
.
It
means
multiple
listeners
can
be
attached
for
listening
the
events
of
a
single
instance
of
Doctrine_Db
.
<
br
\
><
br
\
>
For
example
you
might
want
to
add
different
aspects
to
your
Doctrine_Db
instance
on
-
demand
.
These
aspects
may
include
caching
,
query
profiling
etc
.
<
br
\
><
br
\
>
manual/docs/Basic Components - DB - Connecting to a database.php
View file @
440bef08
<?php
?>
Doctrine_Db allows both PEAR-like DSN (data source name) as well as PDO like DSN as constructor parameters.
<br
\
><br
\
>
Getting an instance of Doctrine_Db using PEAR-like DSN:
<br
\
><br
\
>
<?php
$str
=
"<?php
// using PEAR like dsn for connecting pgsql database
// using PDO like dsn for connecting sqlite memory table
\$
dbh = new Doctrine_Db('pgsql://root:password@localhost/mydb');
$dbh
=
Doctrine_DB
::
getConnection
(
'sqlite::memory:'
);
// using PDO like dsn for connecting pgsql database
// using PEAR like dsn for connecting mysql database
$dbh
=
Doctrine_DB
::
getConnection
(
'pgsql://root:password@localhost/mydb'
);
\$
dbh = new Doctrine_Db('mysql://root:password@localhost/test');
?>"
;
renderCode
(
$str
);
?>
<br
\
><br
\
>
Getting an instance of Doctrine_Db using PDO-like DSN (PDO mysql driver):
<br
\
><br
\
>
<?php
$str
=
"<?php
\$
dbh = new Doctrine_Db('mysql:host=localhost;dbname=test',
\$
user,
\$
pass);
?>"
;
renderCode
(
$str
);
?>
<br
\
><br
\
>
Getting an instance of Doctrine_Db using PDO-like DSN (PDO sqlite with memory tables):
<br
\
>
<br
\
>
<?php
$str
=
"<?php
\$
dbh = new Doctrine_Db('sqlite::memory:');
?>"
;
renderCode
(
$str
);
?>
<br
\
><br
\
>
// using PEAR like dsn for connecting mysql database
Handling connection errors:
$dbh
=
Doctrine_DB
::
getConnection
(
'mysql://root:password@localhost/test'
);
<?php
$str
=
"<?php
try {
\$
dbh = new Doctrine_Db('mysql:host=localhost;dbname=test',
\$
user,
\$
pass);
foreach (
\$
dbh->query('SELECT * FROM foo') as
\$
row) {
print_r(
\$
row);
}
\$
dbh = null;
} catch (PDOException
\$
e) {
print 'Error!: ' .
\$
e->getMessage() . '<br />';
die();
}
?>"
;
renderCode
(
$str
);
?>
manual/docs/Basic Components - DB - Introduction.php
View file @
440bef08
Doctrine_D
B
is
a
wrapper
for
PDO
database
object
.
Why
should
you
consider
using
Doctrine_DB
instead
of
PDO
?
Doctrine_D
b
is
a
wrapper
for
PDO
database
object
.
Why
should
you
consider
using
Doctrine_Db
instead
of
PDO
?
<
br
\
><
br
\
>
1.
It
provides
efficient
eventlistener
architecture
,
hence
its
easy
to
add
new
aspects
to
existing
methods
like
on
-
demand
-
caching
<
br
\
><
br
\
>
2.
Doctrine_D
B
lazy
-
connects
database
.
Creating
an
instance
of
Doctrine_DB
doesn
'
t
directly
connect
database
,
hence
Doctrine_D
B
fits
perfectly
for
application
using
for
example
page
caching
.
2.
Doctrine_D
b
lazy
-
connects
database
.
Creating
an
instance
of
Doctrine_Db
doesn
'
t
directly
connect
database
,
hence
Doctrine_D
b
fits
perfectly
for
application
using
for
example
page
caching
.
<
br
\
><
br
\
>
3.
It
has
many
short
cuts
for
commonly
used
fetching
methods
like
Doctrine_D
B
::
fetchOne
()
.
3.
It
has
many
short
cuts
for
commonly
used
fetching
methods
like
Doctrine_D
b
::
fetchOne
()
.
<
br
\
><
br
\
>
4.
Supports
PEAR
-
like
data
source
names
as
well
as
PDO
data
source
names
.
manual/docs/Basic Components - DB - Using event listeners.php
0 → 100644
View file @
440bef08
<?php
?>
Doctrine_Db has a pluggable event listener architecture. It provides before and after
listeners for all relevant methods. Every listener method takes one parameter: a Doctrine_Db_Event object, which
holds info about the occurred event.
<br
\
><br
\
>
Every listener object must either implement the Doctrine_Db_EventListener_Interface or Doctrine_Overloadable interface.
Using Doctrine_Overloadable interface
only requires you to implement __call() which is then used for listening all the events.
<br
\
><br
\
>
<?php
$str
=
"<?php
class OutputLogger extends Doctrine_Overloadable {
public function __call(
\$
m,
\$
a) {
print
\$
m . ' called!';
}
}
?>"
;
renderCode
(
$str
);
?>
<br
\
><br
\
>
For convience
you may want to make your listener class extend Doctrine_Db_EventListener which has empty listener methods, hence allowing you not to define
all the listener methods by hand. The following listener, 'MyLogger', is used for listening only onPreQuery and onQuery methods.
<br
\
><br
\
>
<?php
$str
=
"<?php
class MyLogger extends Doctrine_Db_EventListener {
public function onPreQuery(Doctrine_Db_Event
\$
event) {
print 'database is going to be queried!';
}
public function onQuery(Doctrine_Db_Event
\$
event) {
print 'executed: ' .
\$
event->getQuery();
}
}
?>"
;
renderCode
(
$str
);
?>
<br
\
><br
\
>
Now the next thing we need to do is bind the eventlistener objects to our database handler.
<br
\
><br
\
>
manual/documentation.php
View file @
440bef08
...
...
@@ -59,15 +59,17 @@ function render_block($name) {
renderCode
(
$c
);
}
}
function
renderCode
(
$c
=
null
)
{
global
$h
;
if
(
!
empty
(
$c
))
{
$h
=
new
PHP_Highlight
;
$h
->
loadString
(
$c
);
print
"<table width=500 border=1 class='dashed' cellpadding=0 cellspacing=0>"
;
print
"<tr><td>"
;
print
$h
->
toHtml
();
$h
->
toHtml
();
print
"</td></tr>"
;
print
"</table>"
;
}
...
...
@@ -197,7 +199,7 @@ $menu = array("Getting started" =>
"Using SQL"
,
"Adding components"
,
"Method overloading"
),
"D
B
"
=>
array
(
"D
b
"
=>
array
(
"Introduction"
,
"Connecting to a database"
,
"Using event listeners"
,
...
...
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