@@ -904,6 +904,57 @@ macro_rules! php_sqlx_impl_driver_inner {
904904 } )
905905 }
906906
907+ /// Describes table columns with their types and metadata.
908+ ///
909+ /// Returns information about each column in the specified table, including
910+ /// name, type, nullability, default value, and ordinal position.
911+ ///
912+ /// # Parameters
913+ /// - `table_name`: Name of the table to describe.
914+ /// - `schema`: Optional schema name. If `None`, uses the database default schema.
915+ ///
916+ /// # Returns
917+ /// An array of associative arrays, each containing:
918+ /// - `name`: Column name
919+ /// - `type`: Database-specific column type (e.g., "varchar(255)", "int")
920+ /// - `nullable`: Whether the column allows NULL values
921+ /// - `default`: Default value for the column, or NULL if none
922+ /// - `ordinal`: Column position (1-based)
923+ ///
924+ /// # Errors
925+ /// Returns an error if:
926+ /// - the table or schema name is invalid (contains invalid characters);
927+ /// - the query fails to execute;
928+ /// - the table does not exist.
929+ pub fn describe_table(
930+ & self ,
931+ table_name: & str ,
932+ schema: Option <& str >,
933+ ) -> $crate:: error:: Result <Vec <Zval >> {
934+ // Validate identifiers to prevent SQL injection
935+ if !is_valid_ident( table_name) {
936+ return Err ( SqlxError :: InvalidIdentifier {
937+ value: table_name. to_string( ) ,
938+ } ) ;
939+ }
940+ if let Some ( s) = schema {
941+ if !is_valid_ident( s) {
942+ return Err ( SqlxError :: InvalidIdentifier {
943+ value: s. to_string( ) ,
944+ } ) ;
945+ }
946+ }
947+
948+ let mut params = BTreeMap :: new( ) ;
949+ params. insert( "table" . to_string( ) , ParameterValue :: String ( table_name. to_string( ) ) ) ;
950+ params. insert(
951+ "schema" . to_string( ) ,
952+ schema. map_or( ParameterValue :: Null , |s| ParameterValue :: String ( s. to_string( ) ) ) ,
953+ ) ;
954+
955+ self . query_all( DESCRIBE_TABLE_QUERY , Some ( params) , Some ( true ) )
956+ }
957+
907958 /// Begins a new SQL transaction and places it into the transaction stack.
908959 ///
909960 /// This method must be called before executing transactional operations
0 commit comments