【发布时间】:2019-11-25 12:38:11
【问题描述】:
你能帮我解决这个问题吗(代码中标记了第 12 行):
( ! ) 可捕获的致命错误:wpdb 类的对象不能是 转换为字符串 C:\OSPanel\domains\ved\wp-content\plugins\ved-currencies\installer.php 在第 12 行
ved-currencies.php
<?php
function installer(){
include('installer.php');
$installer = new Installer;
$installer -> activate();
}
register_activation_hook( __file__, 'installer' );
function deactivate(){
include('installer.php');
$installer = new Installer;
$installer -> deactivate(); ;
}
register_deactivation_hook( __FILE__, 'deactivate' );
installer.php
<?php
class Installer {
private $wpdb;
private $table_name;
private $charset_collate;
public function __construct() {
global $wpdb;
$this->wpdb = $wpdb;
$this->table_name = $this->$wpdb->prefix . 'ved_currencies'; // Line 12
$this->charset_collate = $wpdb->get_charset_collate();
}
public function activate(){
$sql = "CREATE TABLE $this->table_name (
id mediumint(9) NOT NULL AUTO_INCREMENT UNIQUE,
date date not null,
char_code varchar(3) NOT NULL,
name varchar(40) NOT NULL,
nominal int(9) NOT NULL,
value DECIMAL(20,20) NOT NULL,
PRIMARY KEY (date, char_code)
) $this->charset_collate;";
if ( ! function_exists( 'maybe_create_table' ) ) {
require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
}
maybe_create_table( $this->table_name, $sql);
}
public function deactivate(){
$sql = "drop table if exists $this->table_name";
dbDelta($sql);;
}
}
【问题讨论】:
标签: wordpress