Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
phpdts
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Nemo Ma
phpdts
Commits
d59575b9
Commit
d59575b9
authored
Mar 08, 2023
by
Nemo Ma
Committed by
GitHub
Mar 08, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #51 from mccleaner/add-pdo-support
add the support of pdo
parents
78346544
31a3af52
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
318 additions
and
9 deletions
+318
-9
README.md
README.md
+13
-3
config.inc.php
config.inc.php
+4
-4
include/db_pdo.class.php
include/db_pdo.class.php
+299
-0
install.php
install.php
+2
-2
No files found.
README.md
View file @
d59575b9
# 常磐大逃杀(PHP Battle Royale)
A PHP based game emulating the settings and gameplay of the original Battle Royale series, with a lot of original spin and an original story with tons of references to pop culture.
# 安装
需要php5或者7,composer(也可以不需要)。
## 依赖
*
PHP 7.4.30/5.6
*
PDO (PHP Data Objects) extension
*
composer(可选)
## 安装
```
bash
git clone https://github.com/amarillonmc/phpdts.git
cd
phpdts
composer
install
#可选
```
\ No newline at end of file
```
之后打开
`http://domain/path_to_dts/install.php`
根据提示完成后续安装。
config.inc.php
View file @
d59575b9
...
...
@@ -3,13 +3,13 @@
// [EN] Set below parameters according to your account information provided by your hosting
// [CH] 以下变量请根据空间商提供的账号参数修?如有疑问,请联系服务器提供?
$dbhost
=
'
db
'
;
// database server
$dbhost
=
'
localhost
'
;
// database server
// 数据库服务器
$dbuser
=
'root'
;
// database username
// 数据库用户名
$dbpw
=
'
mylittlepony
'
;
// database password
$dbpw
=
''
;
// database password
// 数据库密?
$dbname
=
'acdts3'
;
// database name
...
...
@@ -64,7 +64,7 @@
// [EN] !ATTENTION! Preservation or debugging for developing
// [CH] 切勿修改以下变量,仅供程序开发调试用!
$database
=
'
mysqli
'
;
// 'mysql' for MySQL version and 'pgsql' for PostgreSQL version
$database
=
'
pdo
'
;
// 'mysql' for MySQL version and 'pgsql' for PostgreSQL version
// MySQL 版本请设?'mysql', PgSQL 版本请设?'pgsql'
$charset
=
'utf-8'
;
// default character set, 'gbk', 'big5', 'utf-8' are available
...
...
@@ -93,7 +93,7 @@
$errorinfo
=
0
;
//是否开启错误信息提示,1为开启,0为关闭。开启会泄漏游戏安装路径
// 以下为salt,请勿修改。
$salt
=
'
281bf5959e8b8f6979295c45f53da1c3
'
;
$salt
=
'
3012becebcc626720409336f6375bcdd
'
;
// ============================================================================
...
...
include/db_pdo.class.php
0 → 100644
View file @
d59575b9
<?php
if
(
!
defined
(
'IN_GAME'
))
{
exit
(
'Access Denied'
);
}
class
dbstuff
{
private
$con
=
NULL
;
private
$stmt
=
NULL
;
public
$query_log
=
array
();
function
connect
(
$dbhost
,
$dbuser
,
$dbpw
,
$dbname
=
''
,
$pconnect
=
0
)
{
try
{
$dsn
=
"mysql:host=
$dbhost
;dbname=
$dbname
"
;
$options
=
[
PDO
::
ATTR_ERRMODE
=>
PDO
::
ERRMODE_EXCEPTION
,
PDO
::
ATTR_EMULATE_PREPARES
=>
false
,
];
$this
->
con
=
new
PDO
(
$dsn
,
$dbuser
,
$dbpw
,
$options
);
}
catch
(
PDOException
$e
)
{
$this
->
halt
(
$e
->
getMessage
());
}
global
$charset
,
$dbcharset
;
if
(
!
$dbcharset
&&
in_array
(
strtolower
(
$charset
),
array
(
'gbk'
,
'big5'
,
'utf-8'
)))
{
$dbcharset
=
str_replace
(
'-'
,
''
,
$charset
);
}
if
(
$dbcharset
)
{
$this
->
con
->
exec
(
"SET character_set_connection=
$dbcharset
, character_set_results=
$dbcharset
, character_set_client=
$dbcharset
"
);
}
$this
->
con
->
exec
(
"SET sql_mode=''"
);
}
function
select_db
(
$dbname
)
{
return
true
;
// PDO selects the database upon connection
}
function
fetch_array
(
$query
,
$result_type
=
PDO
::
FETCH_ASSOC
)
{
return
$query
->
fetch
(
$result_type
);
}
function
query
(
$sql
,
$type
=
''
)
{
if
(
!
empty
(
debug_backtrace
()[
0
][
'file'
]))
{
$this
->
query_log
[]
=
$sql
.
' from '
.
debug_backtrace
()[
0
][
'file'
]
.
' : '
.
debug_backtrace
()[
0
][
'line'
];
}
else
{
$this
->
query_log
[]
=
$sql
;
}
try
{
$sth
=
$this
->
con
->
prepare
(
$sql
);
$result
=
$sth
->
execute
();
if
(
strpos
(
$sql
,
'UPDATE'
)
===
0
)
{
if
(
strpos
(
$sql
,
'users'
)
!==
false
&&
strpos
(
$sql
,
'room'
)
!==
false
)
{
$bk
=
debug_backtrace
();
global
$now
;
}
}
if
(
!
$result
&&
$type
!=
'SILENT'
)
{
$this
->
halt
(
'MySQL Query Error'
,
$sql
);
}
return
$sth
;
}
catch
(
PDOException
$e
)
{
$this
->
halt
(
$e
->
getMessage
(),
$sql
);
}
}
function
queries
(
$queries
,
$ignore_result
=
true
)
{
try
{
$this
->
con
->
beginTransaction
();
$this
->
con
->
exec
(
$this
->
parse_create_table
(
$queries
));
$this
->
con
->
commit
();
}
catch
(
PDOException
$e
)
{
$this
->
con
->
rollBack
();
$this
->
halt
(
$e
->
getMessage
());
}
}
function
parse_create_table
(
$sql
)
{
global
$dbcharset
;
if
(
!
$dbcharset
)
include
GAME_ROOT
.
'./include/modules/core/sys/config/server.config.php'
;
$sql
=
preg_replace
(
"/ENGINE\s*=\s*([a-z]+)/i"
,
"ENGINE=$1 DEFAULT CHARSET="
.
$dbcharset
,
$sql
);
return
$sql
;
}
function
array_insert
(
$dbname
,
$data
,
$on_duplicate_update
=
0
,
$keycol
=
''
){
$tp
=
1
;
//单记录插入
if
(
is_array
(
array_values
(
$data
)[
0
]))
$tp
=
2
;
//多记录插入
$query
=
"INSERT INTO
{
$dbname
}
"
;
$fieldlist
=
$valuelist
=
''
;
if
(
2
!=
$tp
){
//单记录插入
if
(
!
$data
)
return
;
foreach
(
$data
as
$key
=>
$value
)
{
$fieldlist
.=
"
{
$key
}
,"
;
$valuelist
.=
"'
{
$value
}
',"
;
}
if
(
!
empty
(
$fieldlist
)
&&
!
empty
(
$valuelist
)){
$query
.=
'('
.
substr
(
$fieldlist
,
0
,
-
1
)
.
') VALUES ('
.
substr
(
$valuelist
,
0
,
-
1
)
.
')'
;
}
}
else
{
//多记录插入
foreach
(
array_keys
(
array_values
(
$data
)[
0
])
as
$key
)
{
$fieldlist
.=
"
{
$key
}
,"
;
}
foreach
(
$data
as
$dv
){
if
(
!
$dv
)
continue
;
$valuelist
.=
"("
;
foreach
(
$dv
as
$value
)
{
$valuelist
.=
"'
{
$value
}
',"
;
}
$valuelist
=
substr
(
$valuelist
,
0
,
-
1
)
.
'),'
;
}
if
(
!
empty
(
$valuelist
))
{
$query
.=
'('
.
substr
(
$fieldlist
,
0
,
-
1
)
.
') VALUES '
.
substr
(
$valuelist
,
0
,
-
1
);
}
}
if
(
!
empty
(
$query
)
&&
$on_duplicate_update
&&
$keycol
)
{
$query
.=
' ON DUPLICATE KEY UPDATE '
;
$tmp
=
2
==
$tp
?
reset
(
$data
)
:
$data
;
foreach
(
$tmp
as
$key
=>
$value
){
if
(
$key
!==
$keycol
){
$query
.=
'`'
.
$key
.
'`=VALUES(`'
.
$key
.
'`),'
;
}
}
$query
=
substr
(
$query
,
0
,
-
1
);
}
if
(
!
empty
(
$query
))
{
$querystrlen
=
mb_strlen
(
$query
);
if
(
2
==
$tp
&&
sizeof
(
$data
)
>
1
&&
$querystrlen
>
1073000000
)
{
//如果长度超过1M,从中断成两个数组再尝试
//留一点冗余所以不是1073741824
list
(
$data1
,
$data2
)
=
$this
->
arr_query_divide
(
$data
);
$this
->
array_insert
(
$dbname
,
$data1
,
$on_duplicate_update
,
$keycol
);
$this
->
array_insert
(
$dbname
,
$data2
,
$on_duplicate_update
,
$keycol
);
}
else
{
$this
->
query
(
$query
);
}
}
return
$query
;
}
function
arr_query_divide
(
$data
)
{
if
(
sizeof
(
$data
)
<=
1
)
return
$data
;
$offset
=
(
int
)
floor
(
sizeof
(
$data
)
/
2
);
return
array
(
array_slice
(
$data
,
0
,
$offset
),
array_slice
(
$data
,
$offset
));
}
function
array_update
(
$dbname
,
$data
,
$where
,
$o_data
=
NULL
){
//根据$data的键和键值更新数据
$query
=
''
;
foreach
(
$data
as
$key
=>
$value
)
{
if
(
!
is_array
(
$o_data
)
||
!
isset
(
$o_data
[
$key
])
||
$value
!==
$o_data
[
$key
])
$query
.=
"
{
$key
}
= '
{
$value
}
',"
;
}
if
(
!
empty
(
$query
)){
$query
=
"UPDATE
{
$dbname
}
SET "
.
substr
(
$query
,
0
,
-
1
)
.
" WHERE
{
$where
}
"
;
$this
->
query
(
$query
);
}
return
$query
;
}
function
multi_update
(
$dbname
,
$data
,
$confield
,
$singleqry
=
''
){
$fields
=
$range
=
Array
();
foreach
(
$data
as
$rval
){
$con
=
$rval
[
$confield
];
$range
[]
=
"'
$con
'"
;
foreach
(
$rval
as
$fkey
=>
$fval
){
if
(
$fkey
!=
$confield
){
if
(
isset
(
$
{
$fkey
.
'qry'
})){
$
{
$fkey
.
'qry'
}
.=
"WHEN '
$con
' THEN '
$fval
' "
;
}
else
{
$fields
[]
=
$fkey
;
$
{
$fkey
.
'qry'
}
=
"(CASE
$confield
WHEN '
$con
' THEN '
$fval
' "
;
}
}
}
}
$query
=
''
;
foreach
(
$fields
as
$val
){
if
(
!
empty
(
$
{
$val
.
'qry'
})){
$
{
$val
.
'qry'
}
.=
"END) "
;
$query
.=
"
$val
= ${$val.'qry'},"
;
}
}
if
(
!
empty
(
$query
))
{
if
(
$singleqry
){
$singleqry
=
','
.
$singleqry
;}
$query
=
"UPDATE
{
$dbname
}
SET "
.
substr
(
$query
,
0
,
-
1
)
.
"
$singleqry
WHERE
$confield
IN ("
.
implode
(
','
,
$range
)
.
")"
;
$querystrlen
=
mb_strlen
(
$query
);
if
(
sizeof
(
$data
)
>
1
&&
$querystrlen
>
1073000000
)
{
//如果长度超过1M,从中断成两个数组再尝试
list
(
$data1
,
$data2
)
=
$this
->
arr_query_divide
(
$data
);
$this
->
multi_update
(
$dbname
,
$data1
,
$confield
,
$singleqry
);
$this
->
multi_update
(
$dbname
,
$data2
,
$confield
,
$singleqry
);
}
else
{
$this
->
query
(
$query
);
}
}
return
$query
;
}
function
affected_rows
()
{
return
$this
->
con
->
rowCount
();
}
function
error
()
{
return
$this
->
con
->
errorInfo
()[
2
];
}
function
errno
()
{
return
intval
(
$this
->
con
->
errorCode
());
}
function
result
(
$query
,
$row
)
{
$query
->
fetch
(
PDO
::
FETCH_NUM
,
PDO
::
FETCH_ORI_ABS
,
$row
);
return
$query
->
fetchColumn
();
}
function
data_seek
(
$query
,
$row
)
{
if
(
$row
>=
$query
->
rowCount
())
{
return
false
;
}
return
$query
->
fetchColumn
(
0
,
PDO
::
FETCH_ORI_ABS
,
$row
);
}
function
num_rows
(
$query
)
{
return
$query
->
rowCount
();
}
function
num_fields
(
$query
)
{
return
$query
->
columnCount
();
}
function
next_result
(){
return
$this
->
stmt
->
nextRowset
();
}
function
more_results
(){
return
$this
->
stmt
->
nextRowsetExists
();
}
function
store_result
()
{
return
$this
->
con
->
fetchAll
(
PDO
::
FETCH_ASSOC
);
}
function
free_result
(
$query
)
{
$query
->
closeCursor
();
}
function
insert_id
()
{
return
$this
->
con
->
lastInsertId
();
}
function
fetch_row
(
$query
)
{
return
$query
->
fetch
(
PDO
::
FETCH_NUM
);
}
function
fetch_fields
(
$query
)
{
return
$query
->
fetch
(
PDO
::
FETCH_OBJ
);
}
function
version
()
{
return
$this
->
con
->
getAttribute
(
PDO
::
ATTR_SERVER_VERSION
);
}
function
close
()
{
$this
->
con
=
null
;
}
function
halt
(
$message
=
''
,
$sql
=
''
)
{
header
(
'Content-Type: text/HTML; charset=utf-8'
);
echo
'数据库错误。请联系管理员。<br><br>'
;
echo
'类错误信息:'
.
$message
.
'<br>'
;
if
(
!
empty
(
$sql
))
echo
'SQL语句:'
.
$sql
;
echo
'<br><br>'
;
$dberror
=
$this
->
errno
()
.
' '
.
$this
->
error
();
echo
'数据库错误提示:'
.
$dberror
.
'<br><br>'
;
//echo '以下是stack dump<br>';
//var_export(debug_backtrace());
die
();
require_once
GAME_ROOT
.
'./include/db/db_mysqli_error.inc.php'
;
}
function
__destruct
()
{
$this
->
close
();
//file_put_contents(GAME_ROOT.'/query_log.txt', implode("\r\n",$this->query_log)."\r\n\r\n", FILE_APPEND);
}
}
/* End of file db_mysqli.class.php */
/* Location: /include/db/db_mysqli.class.php */
install.php
View file @
d59575b9
...
...
@@ -676,7 +676,7 @@ if(!$action) {
$curr_mysql_version
=
$db
->
result
(
$query
,
0
);
if
(
version_compare
(
$curr_mysql_version
,
'3.23'
,
'<'
))
{
$msg
.=
"<font color=
\"
#FF0000
\"
>
$lang[mysql_version_323]
</font>
\t
"
;
$quit
=
TRUE
;
//
$quit = TRUE;
}
$curr_disk_space
=
intval
(
diskfreespace
(
'.'
)
/
(
1024
*
1024
))
.
'M'
;
...
...
@@ -759,7 +759,7 @@ if(!$action) {
$dbpriv_droptable
=
$lang
[
'yes'
];
}
$query
-
$db
->
query
(
"SELECT COUNT(*) FROM
$tablepre
"
.
"users"
,
'SILENT'
);
//
$query - $db->query("SELECT COUNT(*) FROM $tablepre"."users", 'SILENT');
if
(
!
$db
->
error
())
{
$msg
.=
"<font color=
\"
#FF0000
\"
>
$lang[db_not_null]
</font>
\t
"
;
$alert
=
" onSubmit=
\"
return confirm('
$lang[db_drop_table_confirm]
');
\"
"
;
...
...
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