Switch language

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




maybe_add_column [ WordPress Function ]

maybe_add_column ( $table_name, $column_name, $create_ddl )
Defined at:



* maybe_add_column() * Add column to db table if it doesn't exist.

  • Returns: true if already exists or on successful completion
  • false on error

Source


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

Examples [ wp-snippets.com ]

Google Arama Sonuçlarý

Dahasý ...

0 User Note(s)

Henüz yok. Ýlk sen ol!

Yeni Ekle ...



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