Redshift驱动
浏览:1881
最后更新:2017-06-28 18:30
分类:驱动
在thinkphp中,如果直接用pgsql连接,是没问题,但是TP有一个获取表字段信息的过程,这个过程Pgsql.php中的 getFields方法,在Redshift会报错,主要原因是,redshift不支持table_msg方法。
因此如果项目使用了Redshift数据库,需要增加Redshift扩展
<?php
namespace think\db\driver;
use think\db\Driver;
/**
* Redshift数据库驱动
*/
class Redshift extends Pgsql
{
/**
* 取得数据表的字段信息
* @access public
* @return array
*/
public function getFields($tableName)
{
list($tableName) = explode(' ', $tableName);
$result = $this->query("select \"column\",\"type\",\"notnull\" from pg_table_def where schemaname = 'public' and tablename = '".$tableName."';");
$info = [];
if ($result) {
foreach ($result as $val) {
$info[$val['column']] = [
'name' => $val['column'],
'type' => $val['type'],
'notnull' => $val['notnull'],
//'default' => $val['default'],
'primary' => '',
'autoinc' => '',
];
}
}
return $info;
}
}