Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongo-php-library
Project
Project
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
sinan
mongo-php-library
Commits
bb17999f
Commit
bb17999f
authored
Dec 08, 2014
by
Hannes Magnusson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
improve throw/catch frequency
parent
f5619622
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
33 additions
and
2 deletions
+33
-2
write.php
examples/write.php
+33
-2
No files found.
examples/write.php
View file @
bb17999f
...
...
@@ -24,6 +24,16 @@ $bobby = array(
"nick"
=>
"Bobby Fischer"
,
"citizen"
=>
"USA"
,
);
$kasparov
=
array
(
"name"
=>
"Garry Kimovich Kasparov"
,
"nick"
=>
"Kasparov"
,
"citizen"
=>
"Russia"
,
);
$spassky
=
array
(
"name"
=>
"Boris Vasilievich Spassky"
,
"nick"
=>
"Spassky"
,
"citizen"
=>
"France"
,
);
try
{
$result
=
$collection
->
insertOne
(
$hannes
);
...
...
@@ -48,7 +58,7 @@ try {
var_dump
(
$document
);
}
}
catch
(
Exception
$e
)
{
echo
$e
->
getMessage
(),
"
\n
"
;
printf
(
"Caught exception '%s', on line %d
\n
"
,
$e
->
getMessage
(),
__LINE__
)
;
exit
;
}
...
...
@@ -69,6 +79,13 @@ try {
var_dump
(
$person
);
}
}
catch
(
Exception
$e
)
{
printf
(
"Caught exception '%s', on line %d
\n
"
,
$e
->
getMessage
(),
__LINE__
);
exit
;
}
try
{
$result
=
$collection
->
updateMany
(
array
(
"citizen"
=>
"Iceland"
),
array
(
'$set'
=>
array
(
"viking"
=>
true
))
...
...
@@ -79,6 +96,14 @@ try {
foreach
(
$result
as
$document
)
{
var_dump
(
$document
);
}
}
catch
(
Exception
$e
)
{
printf
(
"Caught exception '%s', on line %d
\n
"
,
$e
->
getMessage
(),
__LINE__
);
exit
;
}
try
{
echo
"This is the trouble maker
\n
"
;
$result
=
$collection
->
replaceOne
(
array
(
"nick"
=>
"Bobby Fischer"
),
array
(
"name"
=>
"Magnus Carlsen"
,
"nick"
=>
"unknown"
,
"citizen"
=>
"Norway"
)
...
...
@@ -88,14 +113,20 @@ try {
foreach
(
$result
as
$document
)
{
var_dump
(
$document
);
}
}
catch
(
Exception
$e
)
{
printf
(
"Caught exception '%s', on line %d
\n
"
,
$e
->
getMessage
(),
__LINE__
);
exit
;
}
try
{
$result
=
$collection
->
deleteOne
(
$document
);
printf
(
"Deleted: %d (out of expected 1)
\n
"
,
$result
->
getNumRemoved
());
$result
=
$collection
->
deleteMany
(
array
(
"citizen"
=>
"Iceland"
));
printf
(
"Deleted: %d (out of expected 2)
\n
"
,
$result
->
getNumRemoved
());
}
catch
(
Exception
$e
)
{
echo
$e
->
getMessage
(),
"
\n
"
;
printf
(
"Caught exception '%s', on line %d
\n
"
,
$e
->
getMessage
(),
__LINE__
)
;
exit
;
}
...
...
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