wpdb::hide_errors PHP Method

hide_errors() public method

By default database errors are not shown.
See also: wpdb::show_errors()
Since: 0.71
public hide_errors ( ) : boolean
return boolean Whether showing of errors was active
    public function hide_errors()
    {
        $show = $this->show_errors;
        $this->show_errors = false;
        return $show;
    }

Usage Example

Example #1
0
 /**
  * Upgrade routine
  * - Creates log table on plugin activation
  * - Migrates table structure on updates
  */
 public function upgrade()
 {
     $log_db_version = get_option(self::OPTION_DB_VERSION, 0);
     // only run upgrade routine when database version is lower than code version
     if (version_compare(self::DB_VERSION, $log_db_version, '<=')) {
         return;
     }
     global $charset_collate;
     // don't show errors as this would mess with plugin activation
     $this->db->hide_errors();
     // Create table if it does not exist
     $sql = "\n\t\tCREATE TABLE IF NOT EXISTS {$this->table_name} (\n        ID BIGINT(20) NOT NULL AUTO_INCREMENT,\n        email VARCHAR(255) NOT NULL,\n        list_ids VARCHAR(255) NOT NULL,\n        method VARCHAR(255) NOT NULL,\n        type VARCHAR(255) NOT NULL,\n        success TINYINT(1) DEFAULT 1,\n\t\tdata TEXT NULL,\n        related_object_ID BIGINT(20) NULL,\n        url VARCHAR(255) DEFAULT '',\n        datetime timestamp DEFAULT CURRENT_TIMESTAMP,\n        PRIMARY KEY  (ID)\n\t\t) {$charset_collate}";
     $this->db->query($sql);
     // update to v1.0.4
     if (version_compare($log_db_version, '1.0.4', '<=')) {
         // change 'sign-up_form' in 'sign-up-form';
         $this->db->query("UPDATE `{$this->table_name}` SET `signup_type` = 'sign-up-form' WHERE `signup_type` = 'sign-up_form'");
     }
     // update to v1.1
     if (version_compare($log_db_version, '1.1', '<=')) {
         // merge columns `form_ID` and `comment_ID` into `related_object_ID`
         $this->db->query("ALTER TABLE `{$this->table_name}` CHANGE COLUMN `form_ID` `related_object_ID` BIGINT(20)");
         $this->db->query("UPDATE `{$this->table_name}` SET `related_object_ID` = `comment_ID` WHERE `related_object_ID` = 0 AND `comment_ID` > 0 ");
         $this->db->query("ALTER TABLE `{$this->table_name}` DROP COLUMN `comment_ID`");
         // add 'success' column
         $this->db->query("ALTER TABLE `{$this->table_name}` ADD COLUMN `success` TINYINT(1) DEFAULT 1");
         // rename columns
         $this->db->query("ALTER TABLE `{$this->table_name}` CHANGE COLUMN `signup_method` `method` VARCHAR(255)");
         $this->db->query("ALTER TABLE `{$this->table_name}` CHANGE COLUMN `signup_type` `type` VARCHAR(255)");
         $this->db->query("ALTER TABLE `{$this->table_name}` CHANGE COLUMN `merge_vars` `data` TEXT");
         // alter datatype of `datetime`
         $this->db->query("ALTER TABLE `{$this->table_name}` CHANGE COLUMN `datetime` `datetime` timestamp DEFAULT CURRENT_TIMESTAMP");
         // change `sign-up-form` to just `form`
         $this->db->query("UPDATE `{$this->table_name}` SET `type` = 'form' WHERE `type` = 'sign-up-form'");
     }
     $this->db->show_errors();
     update_option(self::OPTION_DB_VERSION, self::DB_VERSION);
 }