本文整理汇总了PHP中wp_get_db_schema函数的典型用法代码示例。如果您正苦于以下问题:PHP wp_get_db_schema函数的具体用法?PHP wp_get_db_schema怎么用?PHP wp_get_db_schema使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了wp_get_db_schema函数的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: install_signups
private static function install_signups()
{
global $wpdb;
// Signups is not there and we need it so let's create it
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
// Use WP's core CREATE TABLE query
$create_queries = wp_get_db_schema('ms_global');
if (!is_array($create_queries)) {
$create_queries = explode(';', $create_queries);
$create_queries = array_filter($create_queries);
}
// Filter out all the queries except wp_signups
foreach ($create_queries as $key => $query) {
if (preg_match("|CREATE TABLE ([^ ]*)|", $query, $matches)) {
if (trim($matches[1], '`') !== $wpdb->signups) {
unset($create_queries[$key]);
}
}
}
// Run WordPress's database upgrader
if (!empty($create_queries)) {
dbDelta($create_queries);
}
}
示例2: install_network
function install_network()
{
if (!defined('WP_INSTALLING_NETWORK')) {
define('WP_INSTALLING_NETWORK', true);
}
dbDelta(wp_get_db_schema('global'));
}
示例3: dbDelta
/**
* {@internal Missing Short Description}}
*
* {@internal Missing Long Description}}
*
* @since 1.5.0
*
* @param unknown_type $queries
* @param unknown_type $execute
* @return unknown
*/
function dbDelta($queries = '', $execute = true)
{
global $wpdb;
if (in_array($queries, array('', 'all', 'blog', 'global', 'ms_global'), true)) {
$queries = wp_get_db_schema($queries);
}
// Separate individual queries into an array
if (!is_array($queries)) {
$queries = explode(';', $queries);
$queries = array_filter($queries);
}
/**
* Filter the dbDelta SQL queries.
*
* @since 3.3.0
*
* @param array $queries An array of dbDelta SQL queries.
*/
$queries = apply_filters('dbdelta_queries', $queries);
$cqueries = array();
// Creation Queries
$iqueries = array();
// Insertion Queries
$for_update = array();
// Create a tablename index for an array ($cqueries) of queries
foreach ($queries as $qry) {
if (preg_match("|CREATE TABLE ([^ ]*)|", $qry, $matches)) {
$cqueries[trim($matches[1], '`')] = $qry;
$for_update[$matches[1]] = 'Created table ' . $matches[1];
} else {
if (preg_match("|CREATE DATABASE ([^ ]*)|", $qry, $matches)) {
array_unshift($cqueries, $qry);
} else {
if (preg_match("|INSERT INTO ([^ ]*)|", $qry, $matches)) {
$iqueries[] = $qry;
} else {
if (preg_match("|UPDATE ([^ ]*)|", $qry, $matches)) {
$iqueries[] = $qry;
} else {
// Unrecognized query type
}
}
}
}
}
/**
* Filter the dbDelta SQL queries for creating tables and/or databases.
*
* Queries filterable via this hook contain "CREATE TABLE" or "CREATE DATABASE".
*
* @since 3.3.0
*
* @param array $cqueries An array of dbDelta create SQL queries.
*/
$cqueries = apply_filters('dbdelta_create_queries', $cqueries);
/**
* Filter the dbDelta SQL queries for inserting or updating.
*
* Queries filterable via this hook contain "INSERT INTO" or "UPDATE".
*
* @since 3.3.0
*
* @param array $iqueries An array of dbDelta insert or update SQL queries.
*/
$iqueries = apply_filters('dbdelta_insert_queries', $iqueries);
$global_tables = $wpdb->tables('global');
foreach ($cqueries as $table => $qry) {
// Upgrade global tables only for the main site. Don't upgrade at all if DO_NOT_UPGRADE_GLOBAL_TABLES is defined.
if (in_array($table, $global_tables) && (!is_main_site() || defined('DO_NOT_UPGRADE_GLOBAL_TABLES'))) {
unset($cqueries[$table], $for_update[$table]);
continue;
}
// Fetch the table column structure from the database
$suppress = $wpdb->suppress_errors();
$tablefields = $wpdb->get_results("DESCRIBE {$table};");
$wpdb->suppress_errors($suppress);
if (!$tablefields) {
continue;
}
// Clear the field and index arrays
$cfields = $indices = array();
// Get all of the field names in the query from between the parens
preg_match("|\\((.*)\\)|ms", $qry, $match2);
$qryline = trim($match2[1]);
// Separate field lines into an array
$flds = explode("\n", $qryline);
//echo "<hr/><pre>\n".print_r(strtolower($table), true).":\n".print_r($cqueries, true)."</pre><hr/>";
// For every field line specified in the query
foreach ($flds as $fld) {
//.........这里部分代码省略.........
示例4: get_network_core_table_names
/**
* Get standard network tables
*
* @return array
*/
private function get_network_core_table_names()
{
$schema = wp_get_db_schema('global');
return $this->extract_names_from_schema($schema, $this->wpdb->base_prefix);
}
示例5: bp_core_install_signups
/**
* Install the signups table.
*
* @since BuddyPress (2.0.0)
*
* @global $wpdb
* @uses wp_get_db_schema() to get WordPress ms_global schema
*/
function bp_core_install_signups()
{
global $wpdb;
// Signups is not there and we need it so let's create it
require_once buddypress()->plugin_dir . '/bp-core/admin/bp-core-admin-schema.php';
require_once ABSPATH . 'wp-admin/includes/upgrade.php';
// Never use bp_core_get_table_prefix() for any global users tables
$wpdb->signups = $wpdb->base_prefix . 'signups';
// Use WP's core CREATE TABLE query
$create_queries = wp_get_db_schema('ms_global');
if (!is_array($create_queries)) {
$create_queries = explode(';', $create_queries);
$create_queries = array_filter($create_queries);
}
// Filter out all the queries except wp_signups
foreach ($create_queries as $key => $query) {
if (preg_match("|CREATE TABLE ([^ ]*)|", $query, $matches)) {
if (trim($matches[1], '`') !== $wpdb->signups) {
unset($create_queries[$key]);
}
}
}
// Run WordPress's database upgrader
if (!empty($create_queries)) {
dbDelta($create_queries);
}
}
示例6: dbDelta
/**
* Modifies the database based on specified SQL statements.
*
* Useful for creating new tables and updating existing tables to a new structure.
*
* @since 1.5.0
*
* @global wpdb $wpdb
*
* @param string|array $queries Optional. The query to run. Can be multiple queries
* in an array, or a string of queries separated by
* semicolons. Default empty.
* @param bool $execute Optional. Whether or not to execute the query right away.
* Default true.
* @return array Strings containing the results of the various update queries.
*/
function dbDelta($queries = '', $execute = true)
{
global $wpdb;
if (in_array($queries, array('', 'all', 'blog', 'global', 'ms_global'), true)) {
$queries = wp_get_db_schema($queries);
}
// Separate individual queries into an array
if (!is_array($queries)) {
$queries = explode(';', $queries);
$queries = array_filter($queries);
}
/**
* Filters the dbDelta SQL queries.
*
* @since 3.3.0
*
* @param array $queries An array of dbDelta SQL queries.
*/
$queries = apply_filters('dbdelta_queries', $queries);
$cqueries = array();
// Creation Queries
$iqueries = array();
// Insertion Queries
$for_update = array();
// Create a tablename index for an array ($cqueries) of queries
foreach ($queries as $qry) {
if (preg_match("|CREATE TABLE ([^ ]*)|", $qry, $matches)) {
$cqueries[trim($matches[1], '`')] = $qry;
$for_update[$matches[1]] = 'Created table ' . $matches[1];
} elseif (preg_match("|CREATE DATABASE ([^ ]*)|", $qry, $matches)) {
array_unshift($cqueries, $qry);
} elseif (preg_match("|INSERT INTO ([^ ]*)|", $qry, $matches)) {
$iqueries[] = $qry;
} elseif (preg_match("|UPDATE ([^ ]*)|", $qry, $matches)) {
$iqueries[] = $qry;
} else {
// Unrecognized query type
}
}
/**
* Filters the dbDelta SQL queries for creating tables and/or databases.
*
* Queries filterable via this hook contain "CREATE TABLE" or "CREATE DATABASE".
*
* @since 3.3.0
*
* @param array $cqueries An array of dbDelta create SQL queries.
*/
$cqueries = apply_filters('dbdelta_create_queries', $cqueries);
/**
* Filters the dbDelta SQL queries for inserting or updating.
*
* Queries filterable via this hook contain "INSERT INTO" or "UPDATE".
*
* @since 3.3.0
*
* @param array $iqueries An array of dbDelta insert or update SQL queries.
*/
$iqueries = apply_filters('dbdelta_insert_queries', $iqueries);
$text_fields = array('tinytext', 'text', 'mediumtext', 'longtext');
$blob_fields = array('tinyblob', 'blob', 'mediumblob', 'longblob');
$global_tables = $wpdb->tables('global');
foreach ($cqueries as $table => $qry) {
// Upgrade global tables only for the main site. Don't upgrade at all if conditions are not optimal.
if (in_array($table, $global_tables) && !wp_should_upgrade_global_tables()) {
unset($cqueries[$table], $for_update[$table]);
continue;
}
// Fetch the table column structure from the database
$suppress = $wpdb->suppress_errors();
$tablefields = $wpdb->get_results("DESCRIBE {$table};");
$wpdb->suppress_errors($suppress);
if (!$tablefields) {
continue;
}
// Clear the field and index arrays.
$cfields = $indices = array();
// Get all of the field names in the query from between the parentheses.
preg_match("|\\((.*)\\)|ms", $qry, $match2);
$qryline = trim($match2[1]);
// Separate field lines into an array.
$flds = explode("\n", $qryline);
// For every field line specified in the query.
foreach ($flds as $fld) {
//.........这里部分代码省略.........
示例7: dbDelta
/**
* Modifies the database based on specified SQL statements.
*
* Useful for creating new tables and updating existing tables to a new structure.
*
* @since 1.5.0
*
* @global wpdb $wpdb
*
* @param string|array $queries Optional. The query to run. Can be multiple queries
* in an array, or a string of queries separated by
* semicolons. Default empty.
* @param bool $execute Optional. Whether or not to execute the query right away.
* Default true.
* @return array Strings containing the results of the various update queries.
*/
function dbDelta($queries = '', $execute = true)
{
global $wpdb;
if (in_array($queries, array('', 'all', 'blog', 'global', 'ms_global'), true)) {
$queries = wp_get_db_schema($queries);
}
// Separate individual queries into an array
if (!is_array($queries)) {
$queries = explode(';', $queries);
$queries = array_filter($queries);
}
/**
* Filters the dbDelta SQL queries.
*
* @since 3.3.0
*
* @param array $queries An array of dbDelta SQL queries.
*/
$queries = apply_filters('dbdelta_queries', $queries);
$cqueries = array();
// Creation Queries
$iqueries = array();
// Insertion Queries
$for_update = array();
// Create a tablename index for an array ($cqueries) of queries
foreach ($queries as $qry) {
if (preg_match("|CREATE TABLE ([^ ]*)|", $qry, $matches)) {
$cqueries[trim($matches[1], '`')] = $qry;
$for_update[$matches[1]] = 'Created table ' . $matches[1];
} elseif (preg_match("|CREATE DATABASE ([^ ]*)|", $qry, $matches)) {
array_unshift($cqueries, $qry);
} elseif (preg_match("|INSERT INTO ([^ ]*)|", $qry, $matches)) {
$iqueries[] = $qry;
} elseif (preg_match("|UPDATE ([^ ]*)|", $qry, $matches)) {
$iqueries[] = $qry;
} else {
// Unrecognized query type
}
}
/**
* Filters the dbDelta SQL queries for creating tables and/or databases.
*
* Queries filterable via this hook contain "CREATE TABLE" or "CREATE DATABASE".
*
* @since 3.3.0
*
* @param array $cqueries An array of dbDelta create SQL queries.
*/
$cqueries = apply_filters('dbdelta_create_queries', $cqueries);
/**
* Filters the dbDelta SQL queries for inserting or updating.
*
* Queries filterable via this hook contain "INSERT INTO" or "UPDATE".
*
* @since 3.3.0
*
* @param array $iqueries An array of dbDelta insert or update SQL queries.
*/
$iqueries = apply_filters('dbdelta_insert_queries', $iqueries);
$text_fields = array('tinytext', 'text', 'mediumtext', 'longtext');
$blob_fields = array('tinyblob', 'blob', 'mediumblob', 'longblob');
$global_tables = $wpdb->tables('global');
foreach ($cqueries as $table => $qry) {
// Upgrade global tables only for the main site. Don't upgrade at all if conditions are not optimal.
if (in_array($table, $global_tables) && !wp_should_upgrade_global_tables()) {
unset($cqueries[$table], $for_update[$table]);
continue;
}
// Fetch the table column structure from the database
$suppress = $wpdb->suppress_errors();
$tablefields = $wpdb->get_results("DESCRIBE {$table};");
$wpdb->suppress_errors($suppress);
if (!$tablefields) {
continue;
}
// Clear the field and index arrays.
$cfields = $indices = array();
// Get all of the field names in the query from between the parentheses.
preg_match("|\\((.*)\\)|ms", $qry, $match2);
$qryline = trim($match2[1]);
// Separate field lines into an array.
$flds = explode("\n", $qryline);
// For every field line specified in the query.
foreach ($flds as $fld) {
//.........这里部分代码省略.........
示例8: make_db_sqlite
/**
* Function to create tables according to the schemas of WordPress.
*
* This is executed only once while installation.
*
* @return boolean
*/
function make_db_sqlite()
{
include_once PDODIR . 'query_create.class.php';
include_once ABSPATH . 'wp-admin/includes/schema.php';
$index_array = array();
//ob_end_clean();
$table_schemas = wp_get_db_schema();
$queries = explode(";", $table_schemas);
$query_parser = new CreateQuery();
try {
$pdo = new PDO('sqlite:' . FQDB, null, null, array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
} catch (PDOException $err) {
$err_data = $err->errorInfo;
$message = 'Database connection error!<br />';
$message .= sprintf("Error message is: %s", $err_data[2]);
wp_die($message, 'Database Error!');
}
try {
$pdo->beginTransaction();
foreach ($queries as $query) {
$query = trim($query);
if (empty($query)) {
continue;
}
$rewritten_query = $query_parser->rewrite_query($query);
if (is_array($rewritten_query)) {
$table_query = array_shift($rewritten_query);
$index_queries = $rewritten_query;
$table_query = trim($table_query);
$pdo->exec($table_query);
//foreach($rewritten_query as $single_query) {
// $single_query = trim($single_query);
// $pdo->exec($single_query);
//}
} else {
$rewritten_query = trim($rewritten_query);
$pdo->exec($rewritten_query);
}
}
$pdo->commit();
if ($index_queries) {
// $query_parser rewrites KEY to INDEX, so we don't need KEY pattern
$pattern = '/CREATE\\s*(UNIQUE\\s*INDEX|INDEX)\\s*IF\\s*NOT\\s*EXISTS\\s*(\\w+)?\\s*.*/im';
$pdo->beginTransaction();
foreach ($index_queries as $index_query) {
preg_match($pattern, $index_query, $match);
$index_name = trim($match[2]);
if (in_array($index_name, $index_array)) {
$r = rand(0, 50);
$replacement = $index_name . "_{$r}";
$index_query = str_ireplace('EXISTS ' . $index_name, 'EXISTS ' . $replacement, $index_query);
} else {
$index_array[] = $index_name;
}
$pdo->exec($index_query);
}
$pdo->commit();
}
} catch (PDOException $err) {
$err_data = $err->errorInfo;
$err_code = $err_data[1];
if (5 == $err_code || 6 == $err_code) {
// if the database is locked, commit again
$pdo->commit();
} else {
$pdo->rollBack();
$message = sprintf("Error occured while creating tables or indexes...<br />Query was: %s<br />", var_export($rewritten_query, true));
$message .= sprintf("Error message is: %s", $err_data[2]);
wp_die($message, 'Database Error!');
}
}
$query_parser = null;
$pdo = null;
return true;
}
示例9: test_wp_get_db_schema_does_no_alter_queries_on_existing_install
/**
* @ticket 20263
*/
function test_wp_get_db_schema_does_no_alter_queries_on_existing_install()
{
$updates = dbDelta(wp_get_db_schema());
$this->assertEmpty($updates);
}
示例10: get_core_site_tables
/**
* Get core tables only.
*
* @param bool $do_prefix Should the table names be prefixed?
* @return array
*/
public function get_core_site_tables($do_prefix = TRUE)
{
$cache_key = "site-core-{$this->site_id}-" . ($do_prefix ? 1 : 0);
$cache = wp_cache_get($cache_key, $this->cache_group);
if ($cache) {
return $cache;
}
if ($this->site_id !== get_current_blog_id()) {
switch_to_blog($this->site_id);
}
$schema = wp_get_db_schema('blog', $this->site_id);
$tables = $this->extract_names_from_schema($schema, $this->wpdb->prefix);
if ($do_prefix) {
$tables = $this->prefix_table_names($tables, $this->wpdb->prefix);
}
restore_current_blog();
wp_cache_set($cache_key, $tables, $this->cache_group);
return $tables;
}
示例11: dbDelta
/**
* Modifies the database based on specified SQL statements.
*
* Useful for creating new tables and updating existing tables to a new structure.
*
* @since 1.5.0
*
* @global wpdb $wpdb
*
* @param string|array $queries Optional. The query to run. Can be multiple queries
* in an array, or a string of queries separated by
* semicolons. Default empty.
* @param bool $execute Optional. Whether or not to execute the query right away.
* Default true.
* @return array Strings containing the results of the various update queries.
*/
function dbDelta($queries = '', $execute = true)
{
global $wpdb;
if (in_array($queries, array('', 'all', 'blog', 'global', 'ms_global'), true)) {
$queries = wp_get_db_schema($queries);
}
// Separate individual queries into an array
if (!is_array($queries)) {
if (stristr($queries, "GO") !== FALSE) {
$queries = explode('GO', $queries);
} else {
$queries = explode(';', $queries);
}
$queries = array_filter($queries);
}
foreach ($queries as $query) {
$wpdb->query($query);
}
return array();
}
示例12: wp_get_db_schema
break;
case 'ms_global':
$queries = $ms_global_tables;
break;
case 'all':
default:
$queries = $global_tables . $blog_tables;
break;
}
if (isset($old_blog_id)) {
$wpdb->set_blog_id($old_blog_id);
}
return $queries;
}
// Populate for back compat.
$wp_queries = wp_get_db_schema('all');
/**
* Create WordPress options and set the default values.
*
* @since 1.5.0
*
* @global wpdb $wpdb WordPress database abstraction object.
* @global int $wp_db_version
* @global int $wp_current_db_version
*/
function populate_options()
{
global $wpdb, $wp_db_version, $wp_current_db_version;
$guessurl = wp_guess_url();
/**
* Fires before creating WordPress options and populating their default values.
示例13: site_tables
/**
* Returns an array with the names of all tables for the site with the given ID.
*
* @since 3.0.0
*
* @param int $site_id Site ID.
*
* @return string[] The names of all tables for the site with the given ID.
*/
public function site_tables($site_id)
{
$prefix = $this->db->get_blog_prefix($site_id);
return $this->extract_tables_from_schema(wp_get_db_schema('blog', $site_id), $prefix);
}