Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
Carlos Gonzalez
ISPConfig 3
Commits
0e8a6d59
Commit
0e8a6d59
authored
Aug 15, 2018
by
Jesse Norell
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix db connection test for server.php
parent
8b1b6ecc
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
23 deletions
+47
-23
interface/lib/classes/db_mysql.inc.php
interface/lib/classes/db_mysql.inc.php
+22
-10
server/lib/classes/db_mysql.inc.php
server/lib/classes/db_mysql.inc.php
+22
-10
server/server.php
server/server.php
+3
-3
No files found.
interface/lib/classes/db_mysql.inc.php
View file @
0e8a6d59
...
...
@@ -52,8 +52,7 @@ class db
private
$dbClientFlags
=
0
;
// MySQL Client falgs
/**#@-*/
public
$show_error_messages
=
false
;
// false in server, true in interface
public
$show_error_messages
=
false
;
// false in server, interface sets true when generating templates
/* old things - unused now ////
private $linkId = 0; // last result of mysqli_connect()
...
...
@@ -80,7 +79,7 @@ class db
$this
->
dbUser
=
$user
?
$user
:
$conf
[
'db_user'
];
$this
->
dbPass
=
$pass
?
$pass
:
$conf
[
'db_password'
];
$this
->
dbCharset
=
$conf
[
'db_charset'
];
$this
->
dbClientFlags
=
$flags
?
$flags
:
$conf
[
'db_client_flags'
];
$this
->
dbClientFlags
=
(
$flags
!==
NULL
)
?
$flags
:
$conf
[
'db_client_flags'
];
$this
->
_iConnId
=
mysqli_init
();
mysqli_real_connect
(
$this
->
_iConnId
,
$this
->
dbHost
,
$this
->
dbUser
,
$this
->
dbPass
,
''
,
(
int
)
$this
->
dbPort
,
NULL
,
$this
->
dbClientFlags
);
...
...
@@ -117,6 +116,18 @@ class db
$this
->
_iConnId
=
null
;
}
/*
* Test mysql connection.
*
* @return boolean returns true if db connection is good.
*/
public
function
testConnection
()
{
if
(
mysqli_connect_errno
())
{
return
false
;
}
return
(
boolean
)(
is_object
(
$this
->
_iConnId
)
&&
mysqli_ping
(
$this
->
_iConnId
));
}
/* This allows our private variables to be "read" out side of the class */
public
function
__get
(
$var
)
{
return
isset
(
$this
->
$var
)
?
$this
->
$var
:
NULL
;
...
...
@@ -435,13 +446,14 @@ class db
* @return int id of last inserted row or 0 if none
*/
public
function
insert_id
()
{
$iRes
=
mysqli_query
(
$this
->
_iConnId
,
'SELECT LAST_INSERT_ID() as `newid`'
);
if
(
!
is_object
(
$iRes
))
return
false
;
$aReturn
=
mysqli_fetch_assoc
(
$iRes
);
mysqli_free_result
(
$iRes
);
return
$aReturn
[
'newid'
];
$oResult
=
$this
->
query
(
'SELECT LAST_INSERT_ID() as `newid`'
);
if
(
!
$oResult
)
{
$this
->
_sqlerror
(
'Unable to select last_insert_id()'
);
return
false
;
}
$aReturn
=
$oResult
->
get
();
$oResult
->
free
();
return
isset
(
$aReturn
[
'newid'
])
?
$aReturn
[
'newid'
]
:
0
;
}
...
...
server/lib/classes/db_mysql.inc.php
View file @
0e8a6d59
...
...
@@ -52,8 +52,7 @@ class db
private
$dbClientFlags
=
0
;
// MySQL Client falgs
/**#@-*/
public
$show_error_messages
=
false
;
// false in server, true in interface
public
$show_error_messages
=
false
;
// false in server, interface sets true when generating templates
/* old things - unused now ////
private $linkId = 0; // last result of mysqli_connect()
...
...
@@ -80,7 +79,7 @@ class db
$this
->
dbUser
=
$user
?
$user
:
$conf
[
'db_user'
];
$this
->
dbPass
=
$pass
?
$pass
:
$conf
[
'db_password'
];
$this
->
dbCharset
=
$conf
[
'db_charset'
];
$this
->
dbClientFlags
=
$flags
?
$flags
:
$conf
[
'db_client_flags'
];
$this
->
dbClientFlags
=
(
$flags
!==
NULL
)
?
$flags
:
$conf
[
'db_client_flags'
];
$this
->
_iConnId
=
mysqli_init
();
mysqli_real_connect
(
$this
->
_iConnId
,
$this
->
dbHost
,
$this
->
dbUser
,
$this
->
dbPass
,
''
,
(
int
)
$this
->
dbPort
,
NULL
,
$this
->
dbClientFlags
);
...
...
@@ -117,6 +116,18 @@ class db
$this
->
_iConnId
=
null
;
}
/*
* Test mysql connection.
*
* @return boolean returns true if db connection is good.
*/
public
function
testConnection
()
{
if
(
mysqli_connect_errno
())
{
return
false
;
}
return
(
boolean
)(
is_object
(
$this
->
_iConnId
)
&&
mysqli_ping
(
$this
->
_iConnId
));
}
/* This allows our private variables to be "read" out side of the class */
public
function
__get
(
$var
)
{
return
isset
(
$this
->
$var
)
?
$this
->
$var
:
NULL
;
...
...
@@ -435,13 +446,14 @@ class db
* @return int id of last inserted row or 0 if none
*/
public
function
insert_id
()
{
$iRes
=
mysqli_query
(
$this
->
_iConnId
,
'SELECT LAST_INSERT_ID() as `newid`'
);
if
(
!
is_object
(
$iRes
))
return
false
;
$aReturn
=
mysqli_fetch_assoc
(
$iRes
);
mysqli_free_result
(
$iRes
);
return
$aReturn
[
'newid'
];
$oResult
=
$this
->
query
(
'SELECT LAST_INSERT_ID() as `newid`'
);
if
(
!
$oResult
)
{
$this
->
_sqlerror
(
'Unable to select last_insert_id()'
);
return
false
;
}
$aReturn
=
$oResult
->
get
();
$oResult
->
free
();
return
isset
(
$aReturn
[
'newid'
])
?
$aReturn
[
'newid'
]
:
0
;
}
...
...
server/server.php
View file @
0e8a6d59
...
...
@@ -61,7 +61,7 @@ $conf['server_id'] = intval($conf['server_id']);
/*
* Try to Load the server configuration from the master-db
*/
if
(
$app
->
dbmaster
->
c
onnect
_error
==
NULL
)
{
if
(
$app
->
dbmaster
->
testC
onnect
ion
()
)
{
$server_db_record
=
$app
->
dbmaster
->
queryOneRecord
(
"SELECT * FROM server WHERE server_id = ?"
,
$conf
[
'server_id'
]);
if
(
!
is_array
(
$server_db_record
))
die
(
'Unable to load the server configuration from database.'
);
...
...
@@ -152,7 +152,7 @@ $needStartCore = true;
/*
* Next we try to process the datalog
*/
if
(
$app
->
db
->
c
onnect
_error
==
NULL
&&
$app
->
dbmaster
->
c
onnect
_error
==
NULL
)
{
if
(
$app
->
db
->
testC
onnect
ion
()
&&
$app
->
dbmaster
->
testC
onnect
ion
()
)
{
// Check if there is anything to update
if
(
$conf
[
'mirror_server_id'
]
>
0
)
{
...
...
@@ -187,7 +187,7 @@ if ($app->db->connect_error == NULL && $app->dbmaster->connect_error == NULL) {
$needStartCore
=
false
;
}
else
{
if
(
$app
->
db
->
connect
->
c
onnect
_error
==
NULL
)
{
if
(
!
$app
->
db
->
connect
->
testC
onnect
ion
()
)
{
$app
->
log
(
'Unable to connect to local server.'
.
$app
->
db
->
errorMessage
,
LOGLEVEL_WARN
);
}
else
{
$app
->
log
(
'Unable to connect to master server.'
.
$app
->
dbmaster
->
errorMessage
,
LOGLEVEL_WARN
);
...
...
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