要获取字段,需要将表的名称作为参数

Moh*_*han 9 php codeigniter

我需要获取数据库表的表结构.所以我使用以下代码.

class Some_model extends CI_Model{

    public $DB1;
    function __construct(){
        parent::__construct();
        $this->DB1 = $this->load->database('default',TRUE);
    }

    function getTableStructure($tableName){
        echo $tableName;     //this Outputs my table Name that i pass in the function
        return $this->DB1->field_data($tableName) ;   //this gives error for some tables
    }
}
Run Code Online (Sandbox Code Playgroud)

我收到了数据库错误

要获取字段,需要将表的名称作为参数.

注意:此函数适用于某些表,但我在其他几个表上得到此错误.我正在检查的表是"admin_user"

更新:

我检查了system/database文件夹中DB_driver.php文件中的field_data函数.

当我打印返回对象即

echo "<pre">;print_r($query->field_data());die();
//return $query->field_data();   commented this line print's the object
Run Code Online (Sandbox Code Playgroud)

然而,

//echo "<pre">;print_r($query->field_data());die();  comment this line shows error. 
return $query->field_data();
Run Code Online (Sandbox Code Playgroud)

Sha*_*lam 0

错误消息说明了您错过了什么。
当您收到该错误时,您的 $tableName 为空。
你可以看看system/database/DB_driver.php ,看看field_data(第878行可能是)函数。$table当您的(表名)为空时,您会收到该错误消息。
确保您的表名不为空。