@@ -51,6 +51,14 @@ protected function setUp(): void
5151 )
5252 );
5353 }
54+
55+ $ insertQuery = 'INSERT INTO dbtest (title, description, start_date) VALUES (:title, :description, :start_date) ' ;
56+ $ mysqliStatementObject = new MysqliStatement (static ::$ connection ->getConnection (), $ insertQuery );
57+ $ mysqliStatementObject ->execute ([
58+ ':title ' => 'Test Title ' ,
59+ ':description ' => 'Test Description ' ,
60+ ':start_date ' => '2023-01-01 ' ,
61+ ]);
5462 }
5563
5664 /**
@@ -148,10 +156,45 @@ public function testPreparedStatementWithSingleKey()
148156 $ statement = 'SELECT * FROM dbtest WHERE `title` LIKE :search OR `description` LIKE :search2 ' ;
149157 $ mysqliStatementObject = new MysqliStatement (static ::$ connection ->getConnection (), $ statement );
150158 $ dummyValue = 'test ' ;
151- $ dummyValue2 = 'test ' ;
152159 $ mysqliStatementObject ->bindParam (':search ' , $ dummyValue );
153160 $ mysqliStatementObject ->bindParam (':search2 ' , $ dummyValue );
154161
155162 $ mysqliStatementObject ->execute ();
156163 }
164+
165+ /**
166+ * Regression test to ensure running queries with bound variables still works
167+ */
168+ public function testPreparedStatementWithBinding ()
169+ {
170+ $ statement = 'SELECT id FROM dbtest WHERE `title` LIKE :search ' ;
171+ $ mysqliStatementObject = new MysqliStatement (static ::$ connection ->getConnection (), $ statement );
172+ $ title = 'Test Title ' ;
173+ $ mysqliStatementObject ->bindParam (':search ' , $ title );
174+ $ mysqliStatementObject ->execute ();
175+ $ result = $ mysqliStatementObject ->fetchColumn ();
176+
177+ $ title = 'changed ' ;
178+ $ mysqliStatementObject ->execute ();
179+ $ result2 = $ mysqliStatementObject ->fetchColumn ();
180+ $ this ->assertNotEquals ($ result , $ result2 );
181+ }
182+
183+ /**
184+ * Regression test to ensure running queries with bound variables still works
185+ */
186+ public function testPreparedStatementWithoutBinding ()
187+ {
188+ $ statement = 'SELECT id FROM dbtest WHERE `title` LIKE :search ' ;
189+ $ mysqliStatementObject = new MysqliStatement (static ::$ connection ->getConnection (), $ statement );
190+ $ title = 'Test Title ' ;
191+ $ params = [':search ' => $ title ];
192+ $ mysqliStatementObject ->execute ($ params );
193+ $ result = $ mysqliStatementObject ->fetchColumn ();
194+
195+ $ params [':search ' ] = 'changed ' ;
196+ $ mysqliStatementObject ->execute ($ params );
197+ $ result2 = $ mysqliStatementObject ->fetchColumn ();
198+ $ this ->assertNotEquals ($ result , $ result2 );
199+ }
157200}
0 commit comments