@@ -870,6 +870,31 @@ function ( string $sql, array $params ) {
870870 }
871871 }
872872
873+ /**
874+ * PDO API: Prepare a MySQL statement for execution.
875+ *
876+ * Prepared statements are not implemented yet. Report the standard PDO
877+ * unsupported-function diagnostic instead of using uninitialized parent
878+ * PDO state.
879+ *
880+ * @param string $query The MySQL statement to prepare.
881+ * @param array $options Optional statement options.
882+ * @return PDOStatement|false False when exceptions are disabled.
883+ *
884+ * @throws WP_MySQL_On_SQLite_Exception When exception mode is enabled.
885+ */
886+ #[ReturnTypeWillChange]
887+ public function prepare ( string $ query , array $ options = array () ) {
888+ $ driver_message = 'driver does not support prepared statements ' ;
889+ $ exception = $ this ->new_driver_exception (
890+ 'SQLSTATE[IM001]: Driver does not support this function: ' . $ driver_message ,
891+ 'IM001 ' ,
892+ null ,
893+ array ( 'IM001 ' , 0 , $ driver_message )
894+ );
895+ return $ this ->handle_pdo_error ( $ exception );
896+ }
897+
873898 /**
874899 * PDO API: Translate and execute a MySQL query in SQLite.
875900 *
@@ -1075,16 +1100,7 @@ public function query( string $query, ?int $fetch_mode = null, ...$fetch_mode_ar
10751100 $ e = $ this ->new_driver_exception ( $ e ->getMessage (), $ e ->getCode (), $ e );
10761101 }
10771102
1078- $ this ->error_info = $ e ->errorInfo ; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
1079- $ this ->error_code = $ this ->error_info [0 ];
1080-
1081- if ( PDO ::ERRMODE_EXCEPTION === $ this ->error_mode ) {
1082- throw $ e ;
1083- }
1084- if ( PDO ::ERRMODE_WARNING === $ this ->error_mode ) {
1085- trigger_error ( $ e ->getMessage (), E_USER_WARNING );
1086- }
1087- return false ;
1103+ return $ this ->handle_pdo_error ( $ e );
10881104 } finally {
10891105 // A query that doesn't return any rows or fails sets found rows to 0.
10901106 if ( ! $ this ->is_readonly || isset ( $ e ) ) {
@@ -1652,6 +1668,26 @@ private function snapshot_column_meta(): array {
16521668 }
16531669 }
16541670
1671+ /**
1672+ * Record and report a PDO operation error according to the configured mode.
1673+ *
1674+ * @param WP_MySQL_On_SQLite_Exception $exception The operation error.
1675+ * @return false Always false when the error is not thrown.
1676+ * @throws WP_MySQL_On_SQLite_Exception When exception mode is enabled.
1677+ */
1678+ private function handle_pdo_error ( WP_MySQL_On_SQLite_Exception $ exception ): bool {
1679+ $ this ->error_info = $ exception ->errorInfo ; // phpcs:ignore WordPress.NamingConventions.ValidVariableName.UsedPropertyNotSnakeCase
1680+ $ this ->error_code = $ this ->error_info [0 ];
1681+
1682+ if ( PDO ::ERRMODE_EXCEPTION === $ this ->error_mode ) {
1683+ throw $ exception ;
1684+ }
1685+ if ( PDO ::ERRMODE_WARNING === $ this ->error_mode ) {
1686+ trigger_error ( $ exception ->getMessage (), E_USER_WARNING );
1687+ }
1688+ return false ;
1689+ }
1690+
16551691 /**
16561692 * Translate and execute a MySQL query in SQLite.
16571693 *
0 commit comments