33namespace App \Controller ;
44
55use Doctrine \DBAL \Connection ;
6- use Doctrine \DBAL \FetchMode ;
76use Symfony \Component \HttpFoundation \JsonResponse ;
87use Symfony \Component \HttpFoundation \Request ;
98use Symfony \Component \Routing \Annotation \Route ;
@@ -22,8 +21,7 @@ public function __construct(Connection $connection)
2221
2322 public function db (): JsonResponse
2423 {
25- $ statement = $ this ->connection ->prepare ('SELECT id,randomNumber FROM World WHERE id = ? ' );
26- $ world = $ statement ->execute ([mt_rand (1 , 10000 )]);
24+ $ world = $ this ->connection ->executeQuery ('SELECT id,randomNumber FROM World WHERE id = ? ' , [mt_rand (1 , 10000 )]);
2725
2826 return new JsonResponse ($ world ->fetchAssociative ());
2927 }
@@ -40,7 +38,8 @@ public function queries(Request $request): JsonResponse
4038
4139 $ statement = $ this ->connection ->prepare ('SELECT id,randomNumber FROM World WHERE id = ? ' );
4240 for ($ i = 0 ; $ i < $ queries ; ++$ i ) {
43- $ world = $ statement ->execute ([mt_rand (1 , 10000 )]);
41+ $ statement ->bindValue (1 , mt_rand (1 , 10000 ));
42+ $ world = $ statement ->executeQuery ();
4443 $ worlds [] = $ world ->fetchAssociative ();
4544 }
4645
@@ -61,11 +60,12 @@ public function updates(Request $request): JsonResponse
6160
6261 for ($ i = 0 ; $ i < $ queries ; ++$ i ) {
6362 $ id = mt_rand (1 , 10000 );
64- $ world = $ readStatement ->execute ([$ id ]);
65- $ world = $ world ->fetchAssociative ();
66- $ writeStatement ->execute (
67- [$ world ['randomNumber ' ] = mt_rand (1 , 10000 ), $ id ]
68- );
63+ $ readStatement ->bindValue (1 , $ id );
64+ $ world = $ readStatement ->executeQuery ();
65+ $ world = $ world ->fetchAssociative ();
66+ $ writeStatement ->bindValue (1 , mt_rand (1 , 10000 ));
67+ $ writeStatement ->bindValue (2 , $ id );
68+ $ writeStatement ->executeStatement ();
6969 $ worlds [] = $ world ;
7070 }
7171
0 commit comments