1
1
<?php
2
2
3
- try {
4
- // Replace the placeholder with your Atlas connection string
5
- $ uri = "<connection string> " ;
3
+ // Replace the placeholder with your Atlas connection string
4
+ $ uri = "<connection string> " ;
6
5
7
- // Create a MongoDB client with server API options
8
- $ client = new MongoDB \Client ($ uri , [], [
9
- 'serverApi ' => new MongoDB \Driver \ServerApi ('1 ' )
10
- ]);
6
+ // Create a MongoDB client with server API options
7
+ $ client = new MongoDB \Client ($ uri , [], [
8
+ 'serverApi ' => new MongoDB \Driver \ServerApi ('1 ' )
9
+ ]);
11
10
12
- // Ping the server to verify that the connection works
13
- $ admin = $ client ->admin ;
14
- $ command = new MongoDB \Driver \Command (['ping ' => 1 ]);
15
- $ result = $ admin ->command ($ command )->toArray ();
11
+ // Ping the server to verify that the connection works
12
+ $ admin = $ client ->admin ;
13
+ $ command = new MongoDB \Driver \Command (['ping ' => 1 ]);
14
+ $ result = $ admin ->command ($ command )->toArray ();
16
15
17
- echo json_encode ($ result ), "\n" ;
18
- echo "Pinged your deployment. You successfully connected to MongoDB! \n" ;
19
- } catch (Exception $ e ) {
20
- echo "An exception occurred: " , $ e ->getMessage (), "\n" ;
21
- exit (EXIT_FAILURE );
22
- }
23
- ?>
16
+ echo json_encode ($ result ), "\n" ;
17
+ echo "Pinged your deployment. You successfully connected to MongoDB! \n" ;
18
+
19
+ ?>
0 commit comments