【问题标题】:Iluminate database problem with schema builder hasTable method使用模式构建器哈希表方法阐明数据库问题
【发布时间】:2020-08-30 01:06:34
【问题描述】:

我有一个使用Illuminate数据库组件的遗留代码库。 从文档中可以看出,我应该能够使用 Schema 组件检测底层数据库中是否存在表。

这是我的尝试

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Schema\Builder as SchemaBuilder;

$schema = new SchemaBuilder(Database::getFactory()->getConnection());

然后我对此进行一些测试。

print_r(get_class_methods($schema));

// outputs 

Array ( [0] => __construct [1] => hasTable [2] => hasColumn [3] => getColumnListing [4] => table [5] => create [6] => drop [7] => dropIfExists [8] => rename [9] => getConnection [10] => setConnection [11] => blueprintResolver )

看起来很开心。

那么。

$schema->hasTable('users');

我收到以下错误

PHP message: PHP Fatal error:  Call to a member function compileTableExists() on null in

【问题讨论】:

  • 好像Database::getFactory()->getConnection()->getSchemaGrammar() 返回null。
  • Illuminate\Support\Facades\Schema::connection('mysql')->hasTable('users');怎么样

标签: php laravel illuminate


【解决方案1】:

我最终解决了这个问题。

$schema_builder = $capsule->connection()->getSchemaBuilder();
if($schema_builder->hasTable('users'))
    echo 'table found';
else
    echo 'table not found';

【讨论】:

    猜你喜欢
    • 2016-08-28
    • 2013-04-18
    • 1970-01-01
    • 2011-06-05
    • 1970-01-01
    • 2015-07-05
    • 1970-01-01
    • 1970-01-01
    • 2016-10-06
    相关资源
    最近更新 更多