/** * Show a summary of the used images * * @return void */ function fox_database() { global $bp, $wpdb; ?> <div class="bpa_admin_main_header"><?php _e('Database Load', "foxfire"); ?> </div> <div class="table table_content"> <table> <?php $cls = new FOX_dbUtil(); $result = $cls->getServerStatus($data_group = "dashboard"); foreach ($result as $key => $val) { ?> <tr class="first"> <td class="bpa_admin_stats_a"><?php echo $key; ?> </td> <td class="bpa_admin_stats_b"><?php echo $val; ?> </td> </tr> <?php } ?> </table> </div> <?php }
/** * Builds a query to add or restructure a database table, given an array defining the table's structure * * @version 1.0 * @since 1.0 * * @param array $struct | Structure of the db table, @see class FOX_db header for examples * => VAL @param string 'db_table_name' | Name of the db table * => VAL @param string 'engine' | Name of table db engine * => ARR @param array 'columns' | Array of database column arrays. * => ARR @param string '' | Name of the db column this key describes * => VAL @param string 'format' | Display format of column, usually %s or %d, @see http://php.net/manual/en/function.sprintf.php * => VAL @param string 'type' Build string used in table creation query * => VAL @param bool 'index' True if the column is indexed by the SQL server. False if not. * => ARR @param array 'composite_keys' | Array of composite key arrays * => ARR @param '' | Composite key array * => VAL @param string 'name' | Name of composite key * => VAL @param array 'columns' | Array of column names to use for key * * @return array | Exception on failure. Query string on success. */ public function buildAddTable($struct) { // Switch between unit test mode (pass as array) and // normal mode (pass as class name) // ==================================================== if (is_string($struct)) { $struct = call_user_func(array($struct, '_struct')); } // Check for illegal keys // ==================================================== $cls = new FOX_dbUtil(); foreach ($struct["columns"] as $key => $fake_var) { if ($cls->isReservedWord($key) == true) { throw new FOX_exception(array('numeric' => 1, 'text' => "Tried to use SQL reserved word as column name", 'data' => array("struct" => $struct, "illegal_key" => $key), 'file' => __FILE__, 'class' => __CLASS__, 'function' => __FUNCTION__, 'line' => __LINE__, 'child' => null)); } } unset($key, $fake_var); $charset_collate = ''; if (!empty($this->charset)) { $charset_collate = "DEFAULT CHARACTER SET {$this->charset}"; } if (!empty($this->collate)) { $charset_collate .= " COLLATE {$this->collate}"; } // Trap missing table definition // ==================================================== if (empty($struct["table"])) { throw new FOX_exception(array('numeric' => 2, 'text' => "Missing table definition array", 'data' => array("struct" => $struct), 'file' => __FILE__, 'class' => __CLASS__, 'function' => __FUNCTION__, 'line' => __LINE__, 'child' => null)); } // Trap missing columns array // ==================================================== if (empty($struct["columns"])) { throw new FOX_exception(array('numeric' => 3, 'text' => "Missing columns array", 'data' => array("struct" => $struct), 'file' => __FILE__, 'class' => __CLASS__, 'function' => __FUNCTION__, 'line' => __LINE__, 'child' => null)); } // Build the columns string // ==================================================== $columns_left = count($struct["columns"]) - 1; $keys = array(); $auto_inc_count = 0; $query_columns = ''; foreach ($struct["columns"] as $name => $params) { // Trap missing column name // =========================== if (empty($name)) { throw new FOX_exception(array('numeric' => 4, 'text' => "Missing column name", 'data' => array("columns_array" => $struct["columns"], "name" => $name, "params" => $params), 'file' => __FILE__, 'class' => __CLASS__, 'function' => __FUNCTION__, 'line' => __LINE__, 'child' => null)); } // Trap missing SQL data type // =========================== if (empty($params["sql"])) { throw new FOX_exception(array('numeric' => 5, 'text' => "Missing sql data type. \n", 'data' => array("columns_array" => $struct["columns"], "name" => $name, "params" => $params, "type" => $params["sql"]), 'file' => __FILE__, 'class' => __CLASS__, 'function' => __FUNCTION__, 'line' => __LINE__, 'child' => null)); } // Build the columns string // =========================== $query_columns .= $name . " " . $params["sql"]; if ($params["width"]) { $query_columns .= "(" . $params["width"] . ")"; } if ($params["flags"]) { $query_columns .= " " . $params["flags"]; } if ($params["auto_inc"] == true) { $query_columns .= " AUTO_INCREMENT"; $auto_inc_count++; // Trap multiple auto-incrememt columns // ======================================== if ($auto_inc_count > 1) { throw new FOX_exception(array('numeric' => 6, 'text' => "MySQL tables cannot have more than one auto-increment column", 'data' => array("params" => $params), 'file' => __FILE__, 'class' => __CLASS__, 'function' => __FUNCTION__, 'line' => __LINE__, 'child' => null)); } } if ($params["default"] !== null) { $query_columns .= " DEFAULT '" . $params["default"] . "'"; } if ($columns_left != 0) { $query_columns = $query_columns . ", "; $columns_left--; } // Add indexed columns to keys array if ($params["index"]) { $keys[$name] = $params; } } unset($name, $params); // Build the keys string // --------------------- $keys_string = ''; foreach ($keys as $name => $params) { if ($params["index"] === "PRIMARY") { $keys_string .= ", PRIMARY KEY (" . $name . ")"; } elseif ($params["index"] === "UNIQUE") { $keys_string .= ", UNIQUE KEY " . $name . " (" . $name . ")"; } elseif ($params["index"] === "FULLTEXT") { if ($struct["table"] == "InnoDB") { // From the MySQL site: "InnoDB tables do not support FULLTEXT indexes." // @link http://dev.mysql.com/doc/refman/5.5/en/innodb-restrictions.html // Update: as of 5.6.4 InnoDB tables support FULLTEXT // @link: http://dev.mysql.com/doc/refman/5.6/en/innodb-restrictions.html // throw new FOX_exception( array( // 'numeric'=>7, // 'text'=>"FULLTEXT indices cannot be added to InnoDB tables. \n", // 'data'=> array("params"=>$params), // 'file'=>__FILE__, 'class'=>__CLASS__, 'function'=>__FUNCTION__, 'line'=>__LINE__, // 'child'=>null // )); } $keys_string .= ", FULLTEXT KEY (" . $name . ")"; } elseif (is_array($params["index"])) { if ($params["index"]["index"] === "PRIMARY") { $keys_string .= ", PRIMARY KEY " . $params["index"]["name"] . " ("; } elseif ($params["index"]["index"] === "UNIQUE") { $keys_string .= ", UNIQUE KEY " . $params["index"]["name"] . " ("; } else { $keys_string .= ", KEY " . $params["index"]["name"] . " ("; } $keys_left = count($params["index"]["col"]) - 1; foreach ($params["index"]["col"] as $col) { $keys_string .= $col; if ($keys_left != 0) { $keys_string .= ", "; $keys_left--; } } $keys_string .= ")"; // Handle secondary index on the row // ======================================================================= if ($params["index"]["this_row"]) { if ($params["index"]["this_row"] === "PRIMARY") { $keys_string .= ", PRIMARY KEY (" . $name . ")"; } elseif ($params["index"]["this_row"] === "UNIQUE") { $keys_string .= ", UNIQUE KEY " . $name . " (" . $name . ")"; } elseif ($params["index"]["this_row"] === "FULLTEXT") { if ($struct["table"] == "InnoDB") { // From the MySQL site: "InnoDB tables do not support FULLTEXT indexes." // @link http://dev.mysql.com/doc/refman/5.5/en/innodb-restrictions.html throw new FOX_exception(array('numeric' => 8, 'text' => "FULLTEXT indices cannot be added to InnoDB tables", 'data' => array("params" => $params), 'file' => __FILE__, 'class' => __CLASS__, 'function' => __FUNCTION__, 'line' => __LINE__, 'child' => null)); } $keys_string .= ", FULLTEXT KEY (" . $name . ")"; } elseif ($params["index"]["this_row"] === true) { $keys_string .= ", KEY " . $name . " (" . $name . ")"; } } } else { $keys_string .= ", KEY " . $name . " (" . $name . ")"; } } unset($name, $params); $result = "CREATE TABLE " . $this->base_prefix . $struct["table"] . " ( " . $query_columns . $keys_string . " ) ENGINE=" . $struct["engine"] . " " . $charset_collate . ";"; return $result; }