鍍金池/ 問答/PHP  網(wǎng)絡(luò)安全/ SQLSTATE[42S02]: Base table not found: 1

SQLSTATE[42S02]: Base table not found: 1146

code:

public function getUserFourElemByUid($uid)
    {
        print_r(self::getInstance());
        $user = self::all();
        if (empty($user)) {
            return null;
        }

        return $user->toArray();
    }

其中,print_r函數(shù)打印結(jié)果為:

User_DetailModel Object ( [connection] => licai_user [table] => user_detail_2 [primaryKey] => uid [incrementing] => [timestamps] => 1 [perPage:protected] => 15 [attributes:protected] => Array ( ) [original:protected] => Array ( ) [relations:protected] => Array ( ) [hidden:protected] => Array ( ) [visible:protected] => Array ( ) [appends:protected] => Array ( ) [fillable:protected] => Array ( ) [guarded:protected] => Array ( [0] => * ) [dates:protected] => Array ( ) [casts:protected] => Array ( ) [touches:protected] => Array ( ) [observables:protected] => Array ( ) [with:protected] => Array ( ) [morphClass:protected] => [exists] => ) 

table字段值為user_detail_2沒問題,是我想要查詢的表,但是下面語句報了如下錯誤:

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S02]: Base table or view not found: 1146 Table 'licai_user.lc_user__detail_models' doesn't exist' in /data0/userdata/****/htdocs/finance_licai/vendor/illuminate/database/Connection.php:292 Stack trace: #0 /data0/userdata/****/htdocs/finance_licai/vendor/illuminate/database/Connection.php(292): PDO->prepare('select * from `...') #1 /data0/userdata/****/htdocs/finance_licai/vendor/illuminate/database/Connection.php(616): Illuminate\Database\Connection->Illuminate\Database\{closure}(Object(Illuminate\Database\MySqlConnection), 'select * from `...', Array) #2 /data0/userdata/****/htdocs/finance_licai/vendor/illuminate/database/Connection.php(580): Illuminate\Database\Connection->runQueryCallback('select * from `...', Array, Object(Closure)) #3 /data0/userdata/****/htdocs/finance_licai/vendor/illuminate/database/Connection.php(297): Illuminate\Database\Connection->run('select * in /data0/userdata/****/htdocs/finance_licai/vendor/illuminate/database/Connection.php on line 624

錯誤中提到表:licai_user.lc_user__detail_models不存在,一方面數(shù)據(jù)庫中沒有這個表,另一方面我想要查詢的也不是這個表,而是user_detail_2表。麻煩哪位大神給解決下?

回答
編輯回答
枕邊人

你看看你 self::all() 鏈接的是哪個表,打印出來看看,錯誤不會無故報錯的,仔細(xì)檢查你的代碼

2017年2月28日 16:20