Commit 50cec46b authored by Medicean's avatar Medicean

(Enhance:Database) 新增 php oracle_oci8 连接方式, 用于连接 oracle 8i,9i,10g,11g,12c

> host 部分填写: localhost/orcl 或者 localhost:1521/orcl
> 参考: http://php.net/manual/zh/function.oci-connect.php  connection_string 部分
parent 9776d3f8
...@@ -17,6 +17,11 @@ ...@@ -17,6 +17,11 @@
> 如果直连shell本地sqlserver, host 部分填 localhost 或者 (local) > 如果直连shell本地sqlserver, host 部分填 localhost 或者 (local)
> 如果连接外部,使用 ip,port > 如果连接外部,使用 ip,port
* 新增 php oracle_oci8 连接方式, 用于连接 oracle 8i,9i,10g,11g,12c
> host 部分填写: localhost/orcl 或者 localhost:1521/orcl
> 参考: http://php.net/manual/zh/function.oci-connect.php connection_string 部分
* 优化SQLServer类型数据库默认查询语句 * 优化SQLServer类型数据库默认查询语句
* php数据管理解析数据时自动猜解编码 * php数据管理解析数据时自动猜解编码
......
...@@ -20,6 +20,7 @@ class PHP extends Base { ...@@ -20,6 +20,7 @@ class PHP extends Base {
'database/mssql', 'database/mssql',
'database/sqlsrv', 'database/sqlsrv',
'database/oracle', 'database/oracle',
'database/oracle_oci8',
'database/informix' 'database/informix'
].map((_) => { ].map((_) => {
this.parseTemplate(`./php/template/${_}`); this.parseTemplate(`./php/template/${_}`);
......
...@@ -7,7 +7,7 @@ module.exports = () => ({ ...@@ -7,7 +7,7 @@ module.exports = () => ({
info: info:
`$D=dirname($_SERVER["SCRIPT_FILENAME"]);if($D=="")$D=dirname($_SERVER["PATH_TRANSLATED"]);$R="{$D}\t";if(substr($D,0,1)!="/"){foreach(range("C","Z")as $L)if(is_dir("{$L}:"))$R.="{$L}:";}else{$R.="/";}$R.="\t";$u=(function_exists("posix_getegid"))?@posix_getpwuid(@posix_geteuid()):"";$s=($u)?$u["name"]:@get_current_user();$R.=php_uname();$R.="\t{$s}";echo $R;`, `$D=dirname($_SERVER["SCRIPT_FILENAME"]);if($D=="")$D=dirname($_SERVER["PATH_TRANSLATED"]);$R="{$D}\t";if(substr($D,0,1)!="/"){foreach(range("C","Z")as $L)if(is_dir("{$L}:"))$R.="{$L}:";}else{$R.="/";}$R.="\t";$u=(function_exists("posix_getegid"))?@posix_getpwuid(@posix_geteuid()):"";$s=($u)?$u["name"]:@get_current_user();$R.=php_uname();$R.="\t{$s}";echo $R;`,
probedb: // 检测数据库函数支持 probedb: // 检测数据库函数支持
`$m=array('mysql_close','mysqli_close','mssql_close','sqlsrv_close','ora_close','ifx_close','sqlite_close','pg_close','dba_close','dbmclose','filepro_fieldcount','sybase_close'); `$m=array('mysql_close','mysqli_close','mssql_close','sqlsrv_close','ora_close','oci_close','ifx_close','sqlite_close','pg_close','dba_close','dbmclose','filepro_fieldcount','sybase_close');
foreach ($m as $f) { foreach ($m as $f) {
echo($f."\\t".(function_exists($f)?'1':'0')."\\n"); echo($f."\\t".(function_exists($f)?'1':'0')."\\n");
}`.replace(/\n\s+/g, ''), }`.replace(/\n\s+/g, ''),
......
/**
* 数据库管理模板::oracle oci8 驱动
* i 数据分隔符号 => \t|\t
*
* session_mode: OCI_DEFAULT 0 OCI_SYSOPER 4 OCI_SYSDBA 2
*
*/
module.exports = (arg1, arg2, arg3, arg4, arg5, arg6) => ({
// 显示所有数据库
show_databases: {
_:
`$m=get_magic_quotes_gpc();
$sid=$m?stripslashes($_POST["${arg1}"]):$_POST["${arg1}"];
$usr=$m?stripslashes($_POST["${arg2}"]):$_POST["${arg2}"];
$pwd=$m?stripslashes($_POST["${arg3}"]):$_POST["${arg3}"];
$chs="utf8";
$mod=0;
$H=@oci_connect($usr,$pwd,$sid,$chs,$mod);
if(!$H){
echo("ERROR://".@oci_error()["message"]);
}else{
$q=@oci_parse($H,"SELECT USERNAME FROM ALL_USERS ORDER BY 1");
if(@oci_execute($q)){
while(@oci_fetch($q)){
echo(trim(@oci_result($q,1)).chr(9));
}
}else{
$e=@oci_error($q);
echo("ERROR://{$e['message']} in [{$e['sqltext']}] col:{$e['offset']}");
}
@oci_close($H);
};`.replace(/\n\s+/g, ''),
[arg1]: '#{host}',
[arg2]: '#{user}',
[arg3]: '#{passwd}'
},
// 显示数据库所有表
show_tables: {
_:
`$m=get_magic_quotes_gpc();
$sid=$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}"];
$chs="utf8";
$mod=0;
$sql="SELECT TABLE_NAME FROM (SELECT TABLE_NAME FROM ALL_TABLES WHERE OWNER='{$dbn}' ORDER BY 1)";
$H=@oci_connect($usr,$pwd,$sid,$chs,$mod);
if(!$H){
echo("ERROR://".@oci_error()["message"]);
}else{
$q=@oci_parse($H,$sql);
if(@oci_execute($q)){
while(@oci_fetch($q)){
echo(trim(@oci_result($q,1)).chr(9));
}
}else{
$e=@oci_error($q);
echo("ERROR://{$e['message']} in [{$e['sqltext']}] col:{$e['offset']}");
}
@oci_close($H);
};`.replace(/\n\s+/g, ''),
[arg1]: '#{host}',
[arg2]: '#{user}',
[arg3]: '#{passwd}',
[arg4]: '#{db}'
},
// 显示表字段
show_columns: {
_:
`$m=get_magic_quotes_gpc();
$sid=$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}"];
$sql="SELECT COLUMN_NAME,DATA_TYPE,DATA_LENGTH FROM ALL_TAB_COLUMNS WHERE OWNER='{$dbn}' AND TABLE_NAME='{$tab}' ORDER BY COLUMN_ID";
$chs="utf8";
$mod=0;
$H=@oci_connect($usr,$pwd,$sid,$chs,$mod);
if(!$H){
echo("ERROR://".@oci_error()["message"]);
}else{
$q=@oci_parse($H,$sql);
if(@oci_execute($q)){
while(@oci_fetch($q)){
echo(trim(@oci_result($q,1))." (".@oci_result($q,2)."(".@oci_result($q,3)."))".chr(9));
}
}else{
$e=@oci_error($q);
echo("ERROR://{$e['message']} in [{$e['sqltext']}] col:{$e['offset']}");
}
@oci_close($H);
};`.replace(/\n\s+/g, ''),
[arg1]: '#{host}',
[arg2]: '#{user}',
[arg3]: '#{passwd}',
[arg4]: '#{db}',
[arg5]: '#{table}'
},
// 执行SQL语句
query: {
_:
`$m=get_magic_quotes_gpc();
$sid=$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}"]);
$chs=$m?stripslashes($_POST["${arg6}"]):$_POST["${arg6}"];;
$chs=$chs?$chs:"utf8";
$mod=0;
$H=@oci_connect($usr,$pwd,$sid,$chs,$mod);
if(!$H){
echo("ERROR://".@oci_error()["message"]);
}else{
$q=@oci_parse($H,$sql);
if(@oci_execute($q)) {
$n=oci_num_fields($q);
if($n==0){
echo("Affect Rows\t|\t\r\n".base64_encode(@oci_num_rows($q))."\t|\t\r\n");
}else{
for($i=1;$i<=$n;$i++){
echo(oci_field_name($q,$i)."\t|\t");
}
echo "\r\n";
while ($row = @oci_fetch_array($q, OCI_ASSOC+OCI_RETURN_NULLS)) {
foreach ($row as $item) {
echo($item !== null ? base64_encode($item):"")."\t|\t";
}
echo "\r\n";
}
@oci_free_statement($q);
}
}else{
$e=@oci_error($q);
echo("ERROR://{$e['message']} in [{$e['sqltext']}] col:{$e['offset']}");
}
@oci_close($H);
}`.replace(/\n\s+/g, ''),
[arg1]: '#{host}',
[arg2]: '#{user}',
[arg3]: '#{passwd}',
[arg4]: '#{db}',
[arg5]: '#{base64::sql}',
[arg6]: '#{encode}',
}
})
...@@ -218,6 +218,7 @@ class Database { ...@@ -218,6 +218,7 @@ class Database {
'mssql_close': 'MSSQL', 'mssql_close': 'MSSQL',
'sqlsrv_close': 'SQLSRV', 'sqlsrv_close': 'SQLSRV',
'ora_close': 'ORACLE', 'ora_close': 'ORACLE',
'oci_close': 'ORACLE_OCI8',
'ifx_close': 'INFORMIX', 'ifx_close': 'INFORMIX',
'sqlite_close': 'SQLite', 'sqlite_close': 'SQLite',
'pg_close': 'PostgreSQL', 'pg_close': 'PostgreSQL',
......
...@@ -383,6 +383,7 @@ class PHP { ...@@ -383,6 +383,7 @@ class PHP {
})() } })() }
]}, ]},
{ text: 'ORACLE', value: 'oracle' }, { text: 'ORACLE', value: 'oracle' },
{ text: 'ORACLE_OCI8', value: 'oracle_oci8' },
{ text: 'INFORMIX', value: 'informix' } { text: 'INFORMIX', value: 'informix' }
] }, ] },
{ type: 'input', label: LANG['form']['host'], name: 'host', required: true, value: 'localhost' }, { type: 'input', label: LANG['form']['host'], name: 'host', required: true, value: 'localhost' },
...@@ -592,6 +593,7 @@ class PHP { ...@@ -592,6 +593,7 @@ class PHP {
})() } })() }
]}, ]},
{ text: 'ORACLE', value: 'oracle', selected: conf['type'] === 'oracle' }, { text: 'ORACLE', value: 'oracle', selected: conf['type'] === 'oracle' },
{ text: 'ORACLE_OCI8', value: 'oracle_oci8', selected: conf['type'] === 'oracle_oci8' },
{ text: 'INFORMIX', value: 'informix', selected: conf['type'] === 'informix' } { text: 'INFORMIX', value: 'informix', selected: conf['type'] === 'informix' }
] }, ] },
{ type: 'input', label: LANG['form']['host'], name: 'host', required: true, value: conf['host'] }, { type: 'input', label: LANG['form']['host'], name: 'host', required: true, value: conf['host'] },
......
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