GVKun编程网logo

向Wordpress数据库添加新列(创建wordpress数据库)

24

在本文中,我们将为您详细介绍向Wordpress数据库添加新列的相关知识,并且为您解答关于创建wordpress数据库的疑问,此外,我们还会提供一些关于mysql-数据库-存储自定义变量-典型的wor

在本文中,我们将为您详细介绍向Wordpress数据库添加新列的相关知识,并且为您解答关于创建wordpress数据库的疑问,此外,我们还会提供一些关于mysql-数据库-存储自定义变量-典型的wordpress数据库设计、php – wordpress数据库中的交易、php – 从自定义表单将数据插入WordPress数据库表、php – 加速(慢)巨大的wordpress数据库的有用信息。

本文目录一览:

向Wordpress数据库添加新列(创建wordpress数据库)

向Wordpress数据库添加新列(创建wordpress数据库)

我尝试更新我的插件。因此,我必须升级mysql_table。但是当尝试新列时,程序会获得异常。

这是我当前的表格:

$sql = "CREATE TABLE  {$table_name} (        say_id             int(11)   not null AUTO_INCREMENT,        customer_mail      text      not null,        customer_name  text      not null,        customer_messagge      text      not null,        messagge_date_time  datetime  not null,        PRIMARY KEY (say_id)        )ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1";        require_once(ABSPATH . "wp-admin/includes/upgrade.php");        dbDelta($sql);

现在,我向colum添加多一张桌子。我尝试更改表,一次工作,并添加一列,但又刷新一次,我收到此错误。

这是我的代码

$wpdb->query("ALTER TABLE wp_customer_say ADD say_state INT(1) NOT NULL DEFAULT 1");

这是我的错误

WordPress数据库错误:[重复的列名’say_state’] ALTER TABLE wp_customer_say添加了say_state
INT(1)NOT NULL缺省1

我看到这个错误,想尝试一下;

$query          = $wpdb->query("select * from wp_customer_say");        $respond        = mysql_num_fields( $query );        $column_array   = array();        for($i = 0; $i < $respond ; $i++):            $column_array[]     = mysql_field_name($query,$i);        endfor;        if( !in_array("say_state",$column_array) ):            $wpdb->query("ALTER TABLE wp_customer_say ADD say_state INT(1) NOT NULL DEFAULT 1");        endif;

我得到这个错误。

Warning: mysql_num_fields() expects parameter 1 to be resource, integer given in

请帮忙。谢谢你。对不起,英语不好。

答案1

小编典典

使用此查询。我只使用mysql-standred来通过快速查询获取字段名称,这将解决您的问题:

$row = $wpdb->get_results(  "SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNSWHERE table_name = ''wp_customer_say'' AND column_name = ''say_state''"  );if(empty($row)){   $wpdb->query("ALTER TABLE wp_customer_say ADD say_state INT(1) NOT NULL DEFAULT 1");}

mysql-数据库-存储自定义变量-典型的wordpress数据库设计

mysql-数据库-存储自定义变量-典型的wordpress数据库设计

在典型的WordPress网站中,有些表的末尾以“元”命名.在这些表中,有2列,一列名为“ Meta_key”,一列名为“ Meta_value”.存储了任何种类的变量.

这是一个不好的设计吗?这种设计的好处是什么?缺点是什么?

解决方法:

这完全取决于外部设计-键值表只是存储数据的另一种方式,也是另一种思维方式.就像Nosql.

您必须研究wordpress如何使用这些表.由于从未研究过数据库架构,因此我无法对wordpress进行过多介绍.我签出的代码很有趣,但没什么特别的.

另一方面,Magento在某些部分还使用了键值表,并且该键值表对于特定的设计很有用.并不是说我曾经使用过野兽.

根据我的经验,我得出的结论是,设计中的实际实体都拥有自己的表,而诸如配置数据之类的东西可以放在一个高的薄表中.

懒惰是好事,但不要懒惰.

要考虑的另一件事是为键值表增加一列信息(如果使用ID,则除了ID外).称其为“关系”.这是这种思维的一个良好的开端(不要为它烦恼,因为它有一个深处的兔子洞,里面有奇怪的生物):

http://en.wikipedia.org/wiki/Resource_Description_Framework

php – wordpress数据库中的交易

php – wordpress数据库中的交易

WordPress正在使用 MyISAM存储引擎. MyISAM不支持交易.

wordpress如何维护交易?

我的意思是如果wordpress有两个数据库写操作,它如何确保原子性?

好吧,据我所知,它没有!没有太多问题的唯一原因是,大多数写操作都是通过单个插入或更新完成的(添加注释,创建新帖子……).

一般来说,到目前为止我见过的大多数Web应用程序都不会因为事务,原子性甚至参照完整性而烦恼,这是非常可悲的.一方面令人遗憾的是,如此多的应用程序只依靠纯粹的运气而没有发生任何不好的事情,另一方面它可能会导致这样的印象:所有这些技术在数据库方面都不那么重要.

php – 从自定义表单将数据插入WordPress数据库表

php – 从自定义表单将数据插入WordPress数据库表

我试图通过创建一个表将数据插入wordpress数据库.我创建了表,但是当我尝试从表单插入数据时,它不会插入数据.我已检查数据库连接是否正常,但插入不会发生.有人可以帮我吗?这是我的代码: –

PHP
    require_once('/wp-config.php');
    global $wpdb;

    if(isset($_POST['submit'])){
        $wpdb->insert( 'wp_post_job',array( 'organizationname' =>
        $_POST['organizationname'],'post' => $_POST['post'],'publishfrom' =>
        $_POST['publishfrom'],'publishupto' => $_POST['publishupto'],'qualification1' => $_POST['qualification1'],'qualification2' =>
        $_POST['qualification2'],'qualification3' => $_POST['qualification3'],'qualification4' => $_POST['qualification4'],'experience1' =>
        $_POST['experience1'],'experience2' => $_POST['experience2'],'experience3' => $_POST['experience3'],'training1' => $_POST['training1'],'training2' => $_POST['training2'],'training3' => $_POST['training3'],'training4' => $_POST['training4'],'training5' => $_POST['training5'] ),array( '$s','$s','$s' ) );
    }
?>

PHP
/*
Template Name: Form
*/
?>
PHP global $pc_theme_object; /* Reference theme framework class */ ?>
PHP get_header(); ?>

PHP get_footer(); ?>
最佳答案
将’$s’替换为’%s’

使用此代码

if ( isset( $_POST['submit'] ) ){

         global $wpdb;
         $tablename = $wpdb->prefix.'post_job';

        $wpdb->insert( $tablename,array(
            'organizationname' => $_POST['organizationname'],'publishfrom' => $_POST['publishfrom'],'qualification2' => $_POST['qualification2'],'experience1' => $_POST['experience1'],array( '%s','%s','%s' ) 
        );
    }

php – 加速(慢)巨大的wordpress数据库

php – 加速(慢)巨大的wordpress数据库

我正在测试一个新项目,其中涉及使用wordpress安装,其中有超过150万个帖子,通常帖子内容/标题只有一两行 – 所以很短.

我已经获得了强烈推荐的W3-cache插件,它有很多帮助 – 但是当你第一次登陆页面时,需要40-60才能加载并生成缓存,并且网站包含超过1百万个帖子我猜它们都被缓存了将是一场灾难 – 因为只有大约5%的帖子会被定期查看.

以下是标准版本帖子的内容,我可以做些什么来改变/加速明显的瓶颈?我甚至不确定JOIN在做什么?当然,所有需要发生的事情都是通过ID发布.花了这么长时间的查询看起来像是一个查询来显示一些帖子并根据元数据对它们进行排序 – 我在帖子页面上不需要这些信息?

 [5] => Array
    (
        [0] =>  SELECT   wp_posts.* FROM wp_posts  INNER JOIN wp_postMeta ON (wp_posts.ID = wp_postMeta.post_id) WHERE 1=1  AND wp_posts.post_type = 'post' AND (wp_posts.post_status = 'publish') AND (wp_postMeta.Meta_key = 'wpfp_favorites' ) GROUP BY wp_posts.ID ORDER BY wp_postMeta.Meta_value+0 ASC LIMIT 0, 1
        [1] => 43.2097918987
        [2] => require, require_once, include, get_header, locate_template, load_template, require_once, wp_head, do_action, call_user_func_array, start_post_rel_link, get_boundary_post_rel_link, get_boundary_post, get_posts, WP_Query->query, WP_Query->get_posts, W3_Db->query
    )

[6] => Array
    (
        [0] => SELECT p.* FROM wp_posts AS p  WHERE p.post_date < '0000-00-00 00:00:00' AND p.post_type = 'post' AND p.post_status = 'publish'  ORDER BY p.post_date DESC LIMIT 1
        [1] => 7.29560852051E-5
        [2] => require, require_once, include, get_header, locate_template, load_template, require_once, wp_head, do_action, call_user_func_array, adjacent_posts_rel_link_wp_head, adjacent_posts_rel_link, get_adjacent_post_rel_link, get_adjacent_post, W3_Db->query
    )

[7] => Array
    (
        [0] => SELECT p.* FROM wp_posts AS p  WHERE p.post_date > '0000-00-00 00:00:00' AND p.post_type = 'post' AND p.post_status = 'publish'  ORDER BY p.post_date ASC LIMIT 1
        [1] => 1.78813934326E-5
        [2] => require, require_once, include, get_header, locate_template, load_template, require_once, wp_head, do_action, call_user_func_array, adjacent_posts_rel_link_wp_head, adjacent_posts_rel_link, get_adjacent_post_rel_link, get_adjacent_post, W3_Db->query
    )

[8] => Array
    (
        [0] => SELECT option_value FROM wp_options WHERE option_name = 'theme_mods_twentyeleven' LIMIT 1
        [1] => 1.00135803223E-5
        [2] => require, require_once, include, get_header, locate_template, load_template, require_once, wp_head, do_action, call_user_func_array, _custom_background_cb, get_background_image, get_theme_mod, get_theme_mods, get_option, W3_Db->query
    )

[9] => Array
    (
        [0] => SELECT option_value FROM wp_options WHERE option_name = 'mods_Twenty Eleven' LIMIT 1
        [1] => 8.82148742676E-6
        [2] => require, require_once, include, get_header, locate_template, load_template, require_once, wp_head, do_action, call_user_func_array, _custom_background_cb, get_background_image, get_theme_mod, get_theme_mods, get_option, W3_Db->query
    )

[10] => Array
    (
        [0] => SELECT t.*, tt.* FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('post_format') AND tr.object_id IN (1034759) ORDER BY t.name ASC
        [1] => 1.31130218506E-5
        [2] => require, require_once, include, get_header, locate_template, load_template, require_once, body_class, get_body_class, get_post_format, get_the_terms, wp_get_object_terms, W3_Db->query
    )

[11] => Array
    (
        [0] => SELECT disTINCT post_author FROM wp_posts WHERE post_type = 'post' AND post_status = 'publish' LIMIT 2
        [1] => 1.31130218506E-5
        [2] => require, require_once, include, get_header, locate_template, load_template, require_once, body_class, get_body_class, apply_filters, call_user_func_array, twentyeleven_body_classes, is_multi_author, W3_Db->query
    )

[12] => Array
    (
        [0] => SELECT * FROM wp_posts  WHERE (post_type = 'page' AND post_status = 'publish')  AND ( ID <> 1232798 )    ORDER BY menu_order,wp_posts.post_title ASC
        [1] => 1.00135803223E-5
        [2] => require, require_once, include, get_header, locate_template, load_template, require_once, wp_nav_menu, call_user_func, wp_page_menu, wp_list_pages, get_pages, W3_Db->query
    )

[13] => Array
    (
        [0] => SELECT * FROM wp_users WHERE ID = 4031 LIMIT 1
        [1] => 2.00271606445E-5
        [2] => require, require_once, include, the_post, WP_Query->the_post, setup_postdata, get_userdata, W3_Db->query
    )

[14] => Array
    (
        [0] => SELECT t.*, tt.* FROM wp_terms AS t INNER JOIN wp_term_taxonomy AS tt ON tt.term_id = t.term_id INNER JOIN wp_term_relationships AS tr ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ('post_tag') AND tr.object_id IN (1034759) ORDER BY t.name ASC
        [1] => 1.78813934326E-5
        [2] => require, require_once, include, get_template_part, locate_template, load_template, require, post_class, get_post_class, get_the_tags, get_the_terms, wp_get_object_terms, W3_Db->query
    )

[15] => Array
    (
        [0] => SELECT * FROM wp_comments  WHERE comment_approved = '1' AND comment_post_ID = 1034759 ORDER BY comment_date_gmt ASC 
        [1] => 2.09808349609E-5
        [2] => require, require_once, include, comments_template, get_comments, WP_Comment_Query->query, W3_Db->query
    )

[16] => Array
    (
        [0] => SELECT post_id, Meta_value, post_status FROM wp_postMeta LEFT JOIN wp_posts ON post_id=wp_posts.ID WHERE post_status='publish' AND Meta_key='wpfp_favorites' AND Meta_value > 0 ORDER BY ROUND(Meta_value) DESC LIMIT 0, 5
        [1] => 1.50203704834E-5
        [2] => require, require_once, include, get_sidebar, locate_template, load_template, require_once, dynamic_sidebar, call_user_func_array, wpfp_widget_view, wpfp_list_most_favorited, W3_Db->query
    )

无论上述问题如何,我都是在妈妈的共享主机上 – 显然它不会削减它,我想问的是,如果你在哪里运行这种类型的网站 – 你会选择什么样的服务器规格/托管计划?正在考虑处理这种尺寸的安装?随着几个游客每周开始向前移动.

解决方法:

1)在WAMP上使用MysqLtuner(你不能在没有root的情况下安装在共享主机上)来调优MysqL并更改查询缓存,内存等.这将对WAMP和最终的实时服务器产生巨大的影响. https://github.com/rackerhacker/MySQLTuner-perl

2)确保从数据库中删除帖子/页面修订. WP可以存储许多严重影响数据库速度的修订版.删除帖子/页面修订后,我看到数据库大小下降了90%.

在PHPmyadmin中作为SQL查询运行以删除修订;根据需要更改表前缀:

删除a,b,c
来自wp_posts a
LEFT JOIN wp_term_relationships b ON(a.ID = b.object_id)
LEFT JOIN wp_postMeta c ON(a.ID = c.post_id)
在哪里a.post_type =’修订版’

然后优化所有表.然后添加

define(‘WP_POST_REVISIONS’,FALSE);

靠近wp-config.php的顶部(在打开<?PHP ...之后的某个地方)以禁用将来的修订. 3)增加PHP和WP的内存以获得更好的性能: 将PHP.ini中的memory_limit行编辑为128M: memory_limit = 128M; 或者在.htaccess文件的顶部添加此行: PHP_value memory_limit 128M 如果这不起作用或抛出错误,请在打开<?PHP之后立即在wp-config.php文件顶部附近添加此行 define(‘WP_MEMORY_LIMIT’,’128M’); 4)在最终的VPS上,配置http.conf以获得性能,并可能为MysqL服务器本身使用不同的框.

今天关于向Wordpress数据库添加新列创建wordpress数据库的介绍到此结束,谢谢您的阅读,有关mysql-数据库-存储自定义变量-典型的wordpress数据库设计、php – wordpress数据库中的交易、php – 从自定义表单将数据插入WordPress数据库表、php – 加速(慢)巨大的wordpress数据库等更多相关知识的信息可以在本站进行查询。

本文标签: