如何将非英语字符串(如波斯语)插入Wordpress数据库中的tabale?当我插入波斯字符串时,它显示为"??????"
表格中的字符?代码如下:
-正在创建表:
function fjn_add_polls_table_to_db(){
global $wpdb;
$polls_table = $wpdb->prefix. \'polls\';
if( $wpdb->get_var( "SHOW TABLES LIKE \'{$polls_table}\'" ) != $polls_table ){
$query =
"CREATE TABLE {$polls_table} (
poll_id BIGINT(20) UNSIGNED ZEROFILL AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(128),
author_id TINYINT(4) ,
all_votes BIGINT(20) DEFAULT 0
);";
require_once( ABSPATH. \'wp-admin/includes/upgrade.php\' );
dbDelta( $query );
}
}
register_activation_hook(__FILE__, \'fjn_add_polls_table_to_db\');
-插入:
function add_records_to_db(){
global $wpdb;
global $post;
$pid=get_the_ID();
$ptitle=get_the_title();
$aid=$post->post_author;
$wpdb->insert(
\'wp_polls\',
array(
\'poll_id\' => $pid ,
\'title\' => $ptitle,
\'author_id\' => $aid,
\'all_votes\' => "",
),
array(
\'%d\',
\'%s\',
\'%d\',
\'%d\'
)
);
}
add_action( \'publish_poll\', \'add_records_to_db\');
请注意
$ptitle
是非英语字符串。