我是 PHP OOP 的新手,但以下 PHP 代码返回以下错误,我不知道为什么。如果有人能指出什么可能是一个明显的错误,我将不胜感激
致命错误:调用 C:\tester 中未定义的函数 get_column_names()
class tester
{
public $database_name;
public $auto_increment_col;
public $foreign_key_array;
public $column_names;
function __construct($wpdb,$tablename)
{
$this->database_name = get_database_name();
$this->auto_increment_col = get_auto_increment_field($tablename);
$this->foreign_key_array = get_foreign_keys($tablename);
//$this->column_names = $wpdb->get_results( "SHOW COLUMNS FROM $tablename");
$this->column_names = get_column_names($wpdb,$tablename);
}
protected function get_column_names($wpdb,$tablename)
{
return $wpdb->get_results( "SHOW COLUMNS FROM $tablename");
}
protected function get_database_name()
{
$r = mysql_query("SELECT DATABASE()") or die(mysql_error());
return mysql_result($r, 0);
}
protected function get_auto_increment_field($tablename)
{
$sql = "describe $tablename";
$result = mysql_query($sql);
while ($row = mysql_fetch_assoc($result))
{
if ($row['Extra'] == 'auto_increment')
{
return($row['Field']);
}
}
return(null);
}
protected function get_foreign_keys($wpdb,$tablename)
{
$foreign_keys = array();
$sql = "select *
FROM information_schema.TABLE_CONSTRAINTS i
LEFT JOIN information_schema.KEY_COLUMN_USAGE k ON i.CONSTRAINT_NAME = k.CONSTRAINT_NAME
WHERE i.CONSTRAINT_TYPE = 'FOREIGN KEY'
AND i.TABLE_SCHEMA = DATABASE()
AND i.TABLE_NAME = '$tablename'";
$rows = $wpdb->get_results($sql);
if (count($rows) == 0)
return(null);
else
return($rows);
}
}