Switch language

wpseek.com
A WordPress-centric search engine for devs and theme authors




maybe_drop_column [ WordPress Function ]

maybe_drop_column ( $table_name, $column_name, $drop_ddl )
Parameters:
  • (string) $table_name Table name
  • (string) $column_name Column name
  • (string) $drop_ddl SQL statement to drop column.
Uses:
  • $wpdb
Returns:
  • (bool) False on failure, true on success or doesn't exist.
Defined at:



Drop column from database table, if it exists.

Source


<?php
function maybe_drop_column($table_name$column_name$drop_ddl) {
    global 
$wpdb;
    foreach (
$wpdb->get_col("DESC $table_name",0) as $column ) {
        if (
$column == $column_name) {
            
//found it try to drop it.
            
$wpdb->query($drop_ddl);
            
// we cannot directly tell that whether this succeeded!
            
foreach ($wpdb->get_col("DESC $table_name",0) as $column ) {
                if (
$column == $column_name) {
                    return 
false;
                }
            }
        }
    }
    
// else didn't find it
    
return true;
}
?>

Examples [ wp-snippets.com ]

Top Google zoekresultaten

Meer ...

Gebruikersdiscussies [ wordpress.org ]

0 User Note(s)

Nog geen één. Wees de eerste!

Nieuw toevoegen ...



HTML5 Powered with CSS3 / Styling, Performance & Integration, and Semantics