Yii2 ActiveRecord连接OpenGauss提示表不存在table not exist

2023-11-21 22:12

本文主要是介绍Yii2 ActiveRecord连接OpenGauss提示表不存在table not exist,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1.修改数据库连接信息

文件位置 config/db.php

添加默认Schema

return ['class' => 'yii\db\Connection','dsn' => 'pgsql:host=127.0.0.1;port=5432;dbname=postgres','username' => 'postgres','password' => 'Pass@123','charset' => 'utf8',//'enableSchemaCache' => true,//表结构是否缓存//'schemaCacheDuration' => 86400,//'schemaCache' => 'cache','schemaMap' => ['pgsql'=> ['class'=>'yii\db\pgsql\Schema','defaultSchema' => 'postgres' //默认Schema]]
];

2.修改pgsql的Schema函数

文件位置 vendor/yiisoft/yii2/db/pgsql/Schema.php

修改函数 findColumns($table)

protected function findColumns($table)
{$tableName = $this->db->quoteValue($table->name);$schemaName = $this->db->quoteValue($table->schemaName);$sql = "SELECT * FROM information_schema.columns WHERE table_schema='". $table->schemaName ."' and table_name = '". $table->name ."'";$columns = $this->db->createCommand($sql)->queryAll();if (empty($columns)) {return false;}$prksql = "SELECT tc.constraint_name, tc.table_name, kcu.column_name, ccu.table_name AS foreign_table_name, ccu.column_name AS foreign_column_name FROM information_schema.table_constraints tc JOIN information_schema.key_column_usage kcu ON tc.constraint_name = kcu.constraint_name JOIN information_schema.constraint_column_usage ccu ON ccu.constraint_name = tc.constraint_name WHERE tc.constraint_schema='". $table->schemaName ."' and constraint_type = 'PRIMARY KEY' AND tc.table_name='". $table->name ."'";$prkcolumns = $this->db->createCommand($prksql)->queryAll();foreach ($columns as $column) {if ($this->db->slavePdo->getAttribute(\PDO::ATTR_CASE) === \PDO::CASE_UPPER) {$column = array_change_key_case($column, CASE_LOWER);}if(stripos($column["column_default"], "nextval")!==false && stripos($column["column_default"], "_seq")!==false){$column["is_autoinc"] = 1;}else{$column["is_autoinc"] = 0;}$column["size"] = $column["character_maximum_length"];$column["is_pkey"] = 0;foreach($prkcolumns as $oneprkcol){if($oneprkcol["column_name"]==$column["column_name"]){$column["is_pkey"] = 1;}}$column = $this->loadColumnSchema($column);$table->columns[$column->name] = $column;if ($column->isPrimaryKey) {$table->primaryKey[] = $column->name;if ($table->sequenceName === null && preg_match("/nextval\\('\"?\\w+\"?\.?\"?\\w+\"?'(::regclass)?\\)/", $column->defaultValue) === 1) {$table->sequenceName = preg_replace(['/nextval/', '/::/', '/regclass/', '/\'\)/', '/\(\'/'], '', $column->defaultValue);}$column->defaultValue = null;} elseif ($column->defaultValue) {if ($column->type === 'timestamp' && $column->defaultValue === 'now()') {$column->defaultValue = new Expression($column->defaultValue);} elseif ($column->type === 'boolean') {$column->defaultValue = ($column->defaultValue === 'true');} elseif (strncasecmp($column->dbType, 'bit', 3) === 0 || strncasecmp($column->dbType, 'varbit', 6) === 0) {$column->defaultValue = bindec(trim($column->defaultValue, 'B\''));} elseif (preg_match("/^'(.*?)'::/", $column->defaultValue, $matches)) {$column->defaultValue = $column->phpTypecast($matches[1]);} elseif (preg_match('/^(\()?(.*?)(?(1)\))(?:::.+)?$/', $column->defaultValue, $matches)) {if ($matches[2] === 'NULL') {$column->defaultValue = null;} else {$column->defaultValue = $column->phpTypecast($matches[2]);}} else {$column->defaultValue = $column->phpTypecast($column->defaultValue);}}}return true;
}

这篇关于Yii2 ActiveRecord连接OpenGauss提示表不存在table not exist的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/405453

相关文章

Mac电脑如何通过 IntelliJ IDEA 远程连接 MySQL

《Mac电脑如何通过IntelliJIDEA远程连接MySQL》本文详解Mac通过IntelliJIDEA远程连接MySQL的步骤,本文通过图文并茂的形式给大家介绍的非常详细,感兴趣的朋友跟... 目录MAC电脑通过 IntelliJ IDEA 远程连接 mysql 的详细教程一、前缀条件确认二、打开 ID

Go语言连接MySQL数据库执行基本的增删改查

《Go语言连接MySQL数据库执行基本的增删改查》在后端开发中,MySQL是最常用的关系型数据库之一,本文主要为大家详细介绍了如何使用Go连接MySQL数据库并执行基本的增删改查吧... 目录Go语言连接mysql数据库准备工作安装 MySQL 驱动代码实现运行结果注意事项Go语言执行基本的增删改查准备工作

python连接sqlite3简单用法完整例子

《python连接sqlite3简单用法完整例子》SQLite3是一个内置的Python模块,可以通过Python的标准库轻松地使用,无需进行额外安装和配置,:本文主要介绍python连接sqli... 目录1. 连接到数据库2. 创建游标对象3. 创建表4. 插入数据5. 查询数据6. 更新数据7. 删除

在 Spring Boot 中连接 MySQL 数据库的详细步骤

《在SpringBoot中连接MySQL数据库的详细步骤》本文介绍了SpringBoot连接MySQL数据库的流程,添加依赖、配置连接信息、创建实体类与仓库接口,通过自动配置实现数据库操作,... 目录一、添加依赖二、配置数据库连接三、创建实体类四、创建仓库接口五、创建服务类六、创建控制器七、运行应用程序八

解决hive启动时java.net.ConnectException:拒绝连接的问题

《解决hive启动时java.net.ConnectException:拒绝连接的问题》Hadoop集群连接被拒,需检查集群是否启动、关闭防火墙/SELinux、确认安全模式退出,若问题仍存,查看日志... 目录错误发生原因解决方式1.关闭防火墙2.关闭selinux3.启动集群4.检查集群是否正常启动5.

在Linux系统上连接GitHub的方法步骤(适用2025年)

《在Linux系统上连接GitHub的方法步骤(适用2025年)》在2025年,使用Linux系统连接GitHub的推荐方式是通过SSH(SecureShell)协议进行身份验证,这种方式不仅安全,还... 目录步骤一:检查并安装 Git步骤二:生成 SSH 密钥步骤三:将 SSH 公钥添加到 github

Springboot项目启动失败提示找不到dao类的解决

《Springboot项目启动失败提示找不到dao类的解决》SpringBoot启动失败,因ProductServiceImpl未正确注入ProductDao,原因:Dao未注册为Bean,解决:在启... 目录错误描述原因解决方法总结***************************APPLICA编

Redis客户端连接机制的实现方案

《Redis客户端连接机制的实现方案》本文主要介绍了Redis客户端连接机制的实现方案,包括事件驱动模型、非阻塞I/O处理、连接池应用及配置优化,具有一定的参考价值,感兴趣的可以了解一下... 目录1. Redis连接模型概述2. 连接建立过程详解2.1 连php接初始化流程2.2 关键配置参数3. 最大连

MySQL CTE (Common Table Expressions)示例全解析

《MySQLCTE(CommonTableExpressions)示例全解析》MySQL8.0引入CTE,支持递归查询,可创建临时命名结果集,提升复杂查询的可读性与维护性,适用于层次结构数据处... 目录基本语法CTE 主要特点非递归 CTE简单 CTE 示例多 CTE 示例递归 CTE基本递归 CTE 结

电脑提示d3dx11_43.dll缺失怎么办? DLL文件丢失的多种修复教程

《电脑提示d3dx11_43.dll缺失怎么办?DLL文件丢失的多种修复教程》在使用电脑玩游戏或运行某些图形处理软件时,有时会遇到系统提示“d3dx11_43.dll缺失”的错误,下面我们就来分享超... 在计算机使用过程中,我们可能会遇到一些错误提示,其中之一就是缺失某个dll文件。其中,d3dx11_4