Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
antSword
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
HuangJunbo
antSword
Commits
52783288
Commit
52783288
authored
Mar 17, 2019
by
B0y1n4o4
Committed by
Medicean
Mar 17, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
新增 PHP PostgreSQL_PDO 类型数据库操作
parent
55f7af03
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
148 additions
and
0 deletions
+148
-0
index.js
source/core/php/index.js
+1
-0
postgresql_pdo.js
source/core/php/template/database/postgresql_pdo.js
+141
-0
index.js
source/modules/database/php/index.js
+6
-0
No files found.
source/core/php/index.js
View file @
52783288
...
@@ -22,6 +22,7 @@ class PHP extends Base {
...
@@ -22,6 +22,7 @@ class PHP extends Base {
'database/oracle'
,
'database/oracle'
,
'database/oracle_oci8'
,
'database/oracle_oci8'
,
'database/postgresql'
,
'database/postgresql'
,
'database/postgresql_pdo'
,
'database/informix'
'database/informix'
].
map
((
_
)
=>
{
].
map
((
_
)
=>
{
this
.
parseTemplate
(
`./php/template/
${
_
}
`
);
this
.
parseTemplate
(
`./php/template/
${
_
}
`
);
...
...
source/core/php/template/database/postgresql_pdo.js
0 → 100644
View file @
52783288
/**
* 数据库管理模板::postgresql_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
}
"];
$usr=$m?stripslashes($_POST["
${
arg2
}
"]):$_POST["
${
arg2
}
"];
$pwd=$m?stripslashes($_POST["
${
arg3
}
"]):$_POST["
${
arg3
}
"];
$host=split(':',$hst)[0];
$port=split(':',$hst)[1];
$dbh=new PDO("pgsql:host=$host;port=$port;dbname=postgres;",$usr,$pwd);
if(!$dbh){
echo("ERROR://CONNECT ERROR");
}else{
$query="select datname FROM pg_database where datistemplate='f';";
$result=$dbh->prepare($query);
$result->execute();
while($res=$result->fetch(PDO::FETCH_ASSOC)){
echo(trim($res['datname']).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
}
"];
$usr=$m?stripslashes($_POST["
${
arg2
}
"]):$_POST["
${
arg2
}
"];
$pwd=$m?stripslashes($_POST["
${
arg3
}
"]):$_POST["
${
arg3
}
"];
$dbn=$m?stripslashes($_POST["
${
arg4
}
"]):$_POST["
${
arg4
}
"];
$host=split(':',$hst)[0];
$port=split(':',$hst)[1];
$dbh=new PDO("pgsql:host=$host;port=$port;dbname=$dbn;",$usr,$pwd);
if(!$dbh){
echo("ERROR://CONNECT ERROR");
}else{
$query="SELECT table_name FROM information_schema.tables WHERE table_type='BASE TABLE' AND table_schema NOT IN ('pg_catalog', 'information_schema');";
$result=$dbh->prepare($query);
$result->execute();
while($res=$result->fetch(PDO::FETCH_ASSOC)){
echo(trim($res['table_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
}
"];
$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
}
"];
$host=split(':',$hst)[0];
$port=split(':',$hst)[1];
$dbh=new PDO("pgsql:host=$host;port=$port;dbname=$dbn;",$usr,$pwd);
if(!$dbh){
echo("ERROR://CONNECT ERROR");
}else{
$query="SELECT column_name,udt_name,character_maximum_length FROM information_schema.COLUMNS WHERE TABLE_NAME = '{$tab}';";
$result=$dbh->prepare($query);
$result->execute();
while($res=$result->fetch(PDO::FETCH_ASSOC)){
$len=$res['character_maximum_length'] ? $res['character_maximum_length']:"0";
echo(trim($res['column_name'])." ({$res['udt_name']}({$len}))".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
}
"];
$host=split(':',$hst)[0];
$port=split(':',$hst)[1];
$dbh=new PDO("pgsql:host=$host;port=$port;dbname=$dbn;",$usr,$pwd);
if(!$dbh){
echo("ERROR://CONNECT ERROR");
}else{
$result=$dbh->prepare($sql);
if(!$result->execute()){
echo("Status\t|\t\r\n");
echo(base64_encode("ERROR://EXECUTE ERROR")."\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->rowCount()){
echo("Affect Rows\t|\t\r\n".base64_encode($result->rowCount())."\t|\t\r\n");
}else{
echo("Status\t|\t\r\n");
}
}
}
$dbh = null;
}`
.
replace
(
/
\n\s
+/g
,
''
),
[
arg1
]:
'#{host}'
,
[
arg2
]:
'#{user}'
,
[
arg3
]:
'#{passwd}'
,
[
arg4
]:
'#{db}'
,
[
arg5
]:
'#{base64::sql}'
,
[
arg6
]:
'#{encode}'
}
})
source/modules/database/php/index.js
View file @
52783288
...
@@ -85,6 +85,7 @@ class PHP {
...
@@ -85,6 +85,7 @@ class PHP {
sql
=
`SELECT
${
column
}
FROM
${
db
}
.
${
table
}
WHERE ROWNUM < 20 ORDER BY 1`
;
sql
=
`SELECT
${
column
}
FROM
${
db
}
.
${
table
}
WHERE ROWNUM < 20 ORDER BY 1`
;
break
;
break
;
case
'postgresql'
:
case
'postgresql'
:
case
'postgresql_pdo'
:
sql
=
`SELECT
${
column
}
FROM
${
table
}
ORDER BY 1 DESC LIMIT 20 OFFSET 0;`
;
sql
=
`SELECT
${
column
}
FROM
${
table
}
ORDER BY 1 DESC LIMIT 20 OFFSET 0;`
;
break
;
break
;
default
:
default
:
...
@@ -269,6 +270,7 @@ class PHP {
...
@@ -269,6 +270,7 @@ class PHP {
'oracle'
:
[
'UTF8'
,
'ZHS16GBK'
,
'ZHT16BIG5'
,
'ZHS16GBKFIXED'
,
'ZHT16BIG5FIXED'
],
'oracle'
:
[
'UTF8'
,
'ZHS16GBK'
,
'ZHT16BIG5'
,
'ZHS16GBKFIXED'
,
'ZHT16BIG5FIXED'
],
'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'
],
'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'
],
}
}
}
}
...
@@ -347,6 +349,7 @@ class PHP {
...
@@ -347,6 +349,7 @@ class PHP {
{
text
:
'ORACLE'
,
value
:
'oracle'
},
{
text
:
'ORACLE'
,
value
:
'oracle'
},
{
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
:
'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
)
=>
{
...
@@ -410,6 +413,7 @@ class PHP {
...
@@ -410,6 +413,7 @@ class PHP {
})
})
break
;
break
;
case
'postgresql'
:
case
'postgresql'
:
case
'postgresql_pdo'
:
form
.
setFormData
({
form
.
setFormData
({
host
:
'localhost:5432'
,
host
:
'localhost:5432'
,
user
:
'postgres'
,
user
:
'postgres'
,
...
@@ -535,6 +539,7 @@ class PHP {
...
@@ -535,6 +539,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
:
'ORACLE_OCI8'
,
value
:
'oracle_oci8'
,
selected
:
conf
[
'type'
]
===
'oracle_oci8'
},
{
text
:
'PostgreSQL'
,
value
:
'postgresql'
,
selected
:
conf
[
'type'
]
===
'postgresql'
},
{
text
:
'PostgreSQL'
,
value
:
'postgresql'
,
selected
:
conf
[
'type'
]
===
'postgresql'
},
{
text
:
'PostgreSQL_PDO'
,
value
:
'postgresql_pdo'
,
selected
:
conf
[
'type'
]
===
'postgresql_pdo'
},
{
text
:
'INFORMIX'
,
value
:
'informix'
,
selected
:
conf
[
'type'
]
===
'informix'
}
{
text
:
'INFORMIX'
,
value
:
'informix'
,
selected
:
conf
[
'type'
]
===
'informix'
}
]
},
]
},
{
type
:
'combo'
,
label
:
LANG
[
'form'
][
'encode'
],
name
:
'encode'
,
options
:
((
c
)
=>
{
{
type
:
'combo'
,
label
:
LANG
[
'form'
][
'encode'
],
name
:
'encode'
,
options
:
((
c
)
=>
{
...
@@ -1491,6 +1496,7 @@ class PHP {
...
@@ -1491,6 +1496,7 @@ class PHP {
presql
=
`SELECT * FROM
${
db
}
.
${
table
}
WHERE ROWNUM < 20 ORDER BY 1`
;
presql
=
`SELECT * FROM
${
db
}
.
${
table
}
WHERE ROWNUM < 20 ORDER BY 1`
;
break
;
break
;
case
'postgresql'
:
case
'postgresql'
:
case
'postgresql_pdo'
:
presql
=
`SELECT * FROM
${
table
}
ORDER BY 1 DESC LIMIT 20 OFFSET 0;`
;
presql
=
`SELECT * FROM
${
table
}
ORDER BY 1 DESC LIMIT 20 OFFSET 0;`
;
break
;
break
;
default
:
default
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment