Commit 40f07275 authored by Medicean's avatar Medicean

enhance(Modules/Database): PHP 类型新增 SQLite_PDO 支持

parent c309a434
...@@ -7,10 +7,10 @@ ...@@ -7,10 +7,10 @@
### 核心 ### 核心
* 修复 JSP Shell 无法执行 update/delete/insert 语句问题 * 修复 JSP Shell 无法执行 update/delete/insert 语句问题
## 数据管理 ## 数据管理
* 优化出错提示 * 优化出错提示
* PHP 类型新增 SQLite_PDO 支持
## 2021/03/27 `v(2.1.11.1)` ## 2021/03/27 `v(2.1.11.1)`
......
...@@ -25,6 +25,7 @@ class PHP extends Base { ...@@ -25,6 +25,7 @@ class PHP extends Base {
'database/oracle_oci8', 'database/oracle_oci8',
'database/postgresql', 'database/postgresql',
'database/postgresql_pdo', 'database/postgresql_pdo',
'database/sqlite_pdo',
'database/informix' 'database/informix'
].map((_) => { ].map((_) => {
this.parseTemplate(`./php/template/${_}`); this.parseTemplate(`./php/template/${_}`);
......
/**
* 数据库管理模板:: sqlite3 pdo
* 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}"];
$cs='sqlite:'.$hst;
$dbh=new PDO($cs,'','');
if(!$dbh){
echo("ERROR://CONNECT ERROR");
}else{
echo("main".chr(9));
$dbh=null;
}`.replace(/\n\s+/g, ''),
[arg1]: '#{host}',
[arg2]: '#{user}',
[arg3]: '#{passwd}'
},
// 显示数据库所有表
show_tables: {
_: `$m=get_magic_quotes_gpc();
$hst=$m?stripslashes($_POST["${arg1}"]):$_POST["${arg1}"];
$cs='sqlite:'.$hst;
$dbh=new PDO($cs,'','');
if(!$dbh){
echo("ERROR://CONNECT ERROR");
}else{
$query="select tbl_name from sqlite_master where type='table' order by tbl_name;";
$result=$dbh->prepare($query);
$result->execute();
while($res=$result->fetch(PDO::FETCH_ASSOC)){
echo(trim($res['tbl_name']).chr(9));
}
$dbh=null;
}`.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}"];
$dbn=$m?stripslashes($_POST["${arg4}"]):$_POST["${arg4}"];
$tab=$m?stripslashes($_POST["${arg5}"]):$_POST["${arg5}"];
$cs='sqlite:'.$hst;
$dbh=new PDO($cs,'','');
if(!$dbh){
echo("ERROR://CONNECT ERROR");
}else{
$query="pragma table_info('{$tab}');";
$result=$dbh->prepare($query);
$result->execute();
while($res=$result->fetch(PDO::FETCH_ASSOC)){
echo(trim($res['name'])." ({$res['type']})".chr(9));
}
$dbh = null;
}`.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}"];
$cs='sqlite:'.$hst;
$dbh=new PDO($cs,'','');
if(!$dbh){
echo("ERROR://CONNECT ERROR");
}else{
$result=$dbh->prepare($sql);
if(!$result->execute()){
echo("Status\\t|\\t\\r\\n");
$err="";
foreach(@$result->errorInfo() as $v){
$err.=$v." ";
}
echo(base64_encode("ERROR://".$err)."\\t|\\t\\r\\n");
}else{
$bool=True;
while($res=$result->fetch(PDO::FETCH_ASSOC)){
if($bool){
foreach($res as $key=>$value){
echo($key."\\t|\\t");
}
echo "\\r\\n";
$bool=False;
}
foreach($res as $key=>$value){
echo(base64_encode($value!==NULL?$value:"NULL")."\\t|\\t");
}
echo "\\r\\n";
}
if($bool){
if(!$result->columnCount()){
echo("Affect Rows\\t|\\t\\r\\n".base64_encode($result->rowCount())."\\t|\\t\\r\\n");
}else{
echo("Status\\t|\\t\\r\\n");
echo(base64_encode("ERROR://Table is empty.")."\\t|\\t\\r\\n");
}
}
}
$dbh = null;
}`.replace(/\n\s+/g, ''),
[arg1]: '#{host}',
[arg2]: '#{user}',
[arg3]: '#{passwd}',
[arg4]: '#{db}',
[arg5]: '#{base64::sql}',
[arg6]: '#{encode}'
}
})
\ No newline at end of file
...@@ -270,6 +270,7 @@ class PHP { ...@@ -270,6 +270,7 @@ class PHP {
'oracle_oci8': ['UTF8','ZHS16GBK','ZHT16BIG5','ZHS16GBKFIXED','ZHT16BIG5FIXED'], 'oracle_oci8': ['UTF8','ZHS16GBK','ZHT16BIG5','ZHS16GBKFIXED','ZHT16BIG5FIXED'],
'postgresql': ['utf8', 'big5', 'dec8', 'cp850', 'hp8', 'koi8r', 'latin1', 'latin2', 'ascii', 'euckr', 'gb2312', 'gbk'], 'postgresql': ['utf8', 'big5', 'dec8', 'cp850', 'hp8', 'koi8r', 'latin1', 'latin2', 'ascii', 'euckr', 'gb2312', 'gbk'],
'postgresql_pdo': ['utf8', 'big5', 'dec8', 'cp850', 'hp8', 'koi8r', 'latin1', 'latin2', 'ascii', 'euckr', 'gb2312', 'gbk'], 'postgresql_pdo': ['utf8', 'big5', 'dec8', 'cp850', 'hp8', 'koi8r', 'latin1', 'latin2', 'ascii', 'euckr', 'gb2312', 'gbk'],
'sqlite_pdo': ['utf8'],
'informix': ['utf8', 'big5', 'dec8', 'cp850', 'hp8', 'koi8r', 'latin1', 'latin2', 'ascii', 'euckr', 'gb2312', 'gbk'], 'informix': ['utf8', 'big5', 'dec8', 'cp850', 'hp8', 'koi8r', 'latin1', 'latin2', 'ascii', 'euckr', 'gb2312', 'gbk'],
} }
} }
...@@ -349,6 +350,7 @@ class PHP { ...@@ -349,6 +350,7 @@ class PHP {
{ text: 'ORACLE_OCI8', value: 'oracle_oci8' }, { text: 'ORACLE_OCI8', value: 'oracle_oci8' },
{ text: 'PostgreSQL', value: 'postgresql' }, { text: 'PostgreSQL', value: 'postgresql' },
{ text: 'PostgreSQL_PDO', value: 'postgresql_pdo' }, { text: 'PostgreSQL_PDO', value: 'postgresql_pdo' },
{ text: 'SQLite_PDO', value: 'sqlite_pdo' },
{ text: 'INFORMIX', value: 'informix' } { text: 'INFORMIX', value: 'informix' }
] }, ] },
{ type: 'combo', label: LANG['form']['encode'], name: 'encode', options: ((c) => { { type: 'combo', label: LANG['form']['encode'], name: 'encode', options: ((c) => {
...@@ -425,6 +427,13 @@ class PHP { ...@@ -425,6 +427,13 @@ class PHP {
passwd: '', passwd: '',
}); });
break; break;
case 'sqlite_pdo':
form.setFormData({
host: '/var/www/html/test.db',
user: '',
passwd: '',
});
break;
default: default:
form.setFormData({ form.setFormData({
user: 'dbuser', user: 'dbuser',
......
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