用模式构建器哈希表方法阐明数据库问题
Iluminate database problem with schema builder hasTable method
我有一个使用 illuminate 数据库组件的遗留代码库。
从文档中可以看出,我应该能够使用架构组件检测到底层数据库中是否存在 table。
这是我的尝试
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
最后我解决了这个问题。
$schema_builder = $capsule->connection()->getSchemaBuilder();
if($schema_builder->hasTable('users'))
echo 'table found';
else
echo 'table not found';
我有一个使用 illuminate 数据库组件的遗留代码库。 从文档中可以看出,我应该能够使用架构组件检测到底层数据库中是否存在 table。
这是我的尝试
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
最后我解决了这个问题。
$schema_builder = $capsule->connection()->getSchemaBuilder();
if($schema_builder->hasTable('users'))
echo 'table found';
else
echo 'table not found';