Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
MaarchCourrier
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Redmine
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Harbor Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Maarch
MaarchCourrier
Commits
94005a75
Verified
Commit
94005a75
authored
6 years ago
by
Giovannoni Laurent
Browse files
Options
Downloads
Patches
Plain Diff
FIX pb with persistant connection and static object
parent
81301fdd
No related branches found
No related tags found
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
apps/maarch_entreprise/index.php
+1
-0
1 addition, 0 deletions
apps/maarch_entreprise/index.php
core/class/class_db_pdo.php
+10
-12
10 additions, 12 deletions
core/class/class_db_pdo.php
src/core/models/DatabasePDO.php
+16
-24
16 additions, 24 deletions
src/core/models/DatabasePDO.php
with
27 additions
and
36 deletions
apps/maarch_entreprise/index.php
+
1
−
0
View file @
94005a75
...
...
@@ -325,6 +325,7 @@ if ($_REQUEST['page'] && empty($_REQUEST['triggerAngular'])) {
$cookie
=
\SrcCore\models\AuthenticationModel
::
getCookieAuth
();
if
(
empty
(
$cookie
))
{
header
(
'location: index.php?display=true&page=logout&logout=true'
);
exit
();
}
chdir
(
'../..'
);
$user
=
\User\models\UserModel
::
getByUserId
([
'userId'
=>
$cookie
[
'userId'
],
'select'
=>
[
'password_modification_date'
,
'change_password'
,
'status'
]]);
...
...
This diff is collapsed.
Click to expand it.
core/class/class_db_pdo.php
+
10
−
12
View file @
94005a75
...
...
@@ -51,12 +51,8 @@ class Database extends functions
/**
* Constructor. Connects to the database if connection parameters are available in the session config
*/
public
function
__construct
(
$params
=
[]
)
public
function
__construct
()
{
$persistent
=
true
;
if
(
$params
[
'persistent'
]
==
false
)
{
$persistent
=
false
;
}
$args
=
func_get_args
();
if
(
count
(
$args
)
<
1
||
empty
(
$args
[
0
]))
{
if
(
isset
(
$_SESSION
[
'config'
][
'databaseserver'
]))
{
...
...
@@ -129,7 +125,7 @@ class Database extends functions
if
(
!
isset
(
$args
[
0
][
'password'
]))
{
$this
->
password
=
'postgres'
;
}
else
{
$this
->
password
=
$args
[
0
][
'pass'
];
$this
->
password
=
$args
[
0
][
'pass
word
'
];
}
if
(
!
isset
(
$args
[
0
][
'base'
]))
{
$this
->
database
=
''
;
...
...
@@ -190,11 +186,11 @@ class Database extends functions
// Set options
$options
=
array
(
PDO
::
ATTR_PERSISTENT
=>
$persistent
,
PDO
::
ATTR_PERSISTENT
=>
true
,
PDO
::
ATTR_ERRMODE
=>
PDO
::
ERRMODE_EXCEPTION
,
PDO
::
ATTR_CASE
=>
PDO
::
CASE_LOWER
);
// Create a new PDO instan
a
ce
// Create a new PDO instance
try
{
$this
->
pdo
=
new
PDO
(
$this
->
dsn
,
$this
->
user
,
$this
->
password
,
$options
);
}
catch
(
PDOException
$PDOException
)
{
...
...
@@ -316,7 +312,9 @@ class Database extends functions
*/
public
function
query
(
$queryString
,
$parameters
=
null
,
$catchExceptions
=
false
,
$multi
=
false
)
{
$originalQuery
=
$queryString
;
if
(
$parameters
)
{
$originalData
=
$parameters
;
foreach
(
$parameters
as
$key
=>
$value
)
{
if
(
is_array
(
$value
))
{
//echo $key . $value. '<br />';
...
...
@@ -395,11 +393,11 @@ class Database extends functions
}
else
{
if
(
strpos
(
$PDOException
->
getMessage
(),
'Admin shutdown: 7'
)
!==
false
)
{
//echo 'catch error:' . $PDOException->getMessage() . '<br />';
$db
=
self
::
Database
(
[
'persistent'
=>
false
]
);
if
(
$
withParams
)
{
$
executed
=
$db
->
stmt
->
execute
(
$parameters
);
$db
=
new
Database
();
if
(
$
originalData
)
{
$
db
->
query
(
$originalQuery
,
$originalData
);
}
else
{
$
executed
=
$db
->
stmt
->
execute
(
);
$
db
->
query
(
$originalQuery
);
}
}
else
{
if
(
$_SESSION
[
'config'
][
'debug'
]
==
'true'
)
{
...
...
This diff is collapsed.
Click to expand it.
src/core/models/DatabasePDO.php
+
16
−
24
View file @
94005a75
...
...
@@ -17,22 +17,12 @@ namespace SrcCore\models;
class
DatabasePDO
{
private
static
$pdo
=
null
;
private
$pdo
;
private
static
$type
=
null
;
private
static
$preparedQueries
=
[];
public
function
__construct
(
array
$args
=
[])
{
if
(
!
empty
(
self
::
$pdo
))
{
return
;
}
$persistent
=
true
;
if
(
$args
[
'persistent'
]
==
false
)
{
$persistent
=
false
;
}
$server
=
''
;
$port
=
''
;
$name
=
''
;
...
...
@@ -106,17 +96,17 @@ class DatabasePDO
}
$options
=
[
\PDO
::
ATTR_PERSISTENT
=>
$persistent
,
\PDO
::
ATTR_PERSISTENT
=>
true
,
\PDO
::
ATTR_ERRMODE
=>
\PDO
::
ERRMODE_EXCEPTION
,
\PDO
::
ATTR_CASE
=>
\PDO
::
CASE_LOWER
];
try
{
self
::
$
pdo
=
new
\PDO
(
$dsn
,
$user
,
$password
,
$options
);
$this
->
pdo
=
new
\PDO
(
$dsn
,
$user
,
$password
,
$options
);
}
catch
(
\PDOException
$PDOException
)
{
try
{
$options
[
\PDO
::
ATTR_PERSISTENT
]
=
false
;
self
::
$
pdo
=
new
\PDO
(
$dsn
,
$user
,
$password
,
$options
);
$this
->
pdo
=
new
\PDO
(
$dsn
,
$user
,
$password
,
$options
);
}
catch
(
\PDOException
$PDOException
)
{
throw
new
\Exception
(
$PDOException
->
getMessage
());
}
...
...
@@ -129,11 +119,13 @@ class DatabasePDO
public
function
query
(
$queryString
,
array
$data
=
[])
{
$originalQuery
=
$queryString
;
if
(
self
::
$type
==
'ORACLE'
)
{
$queryString
=
str_ireplace
(
'CURRENT_TIMESTAMP'
,
'SYSDATE'
,
$queryString
);
}
if
(
!
empty
(
$data
))
{
$originalData
=
$data
;
$tmpData
=
[];
foreach
(
$data
as
$key
=>
$value
)
{
if
(
is_array
(
$value
))
{
...
...
@@ -151,7 +143,7 @@ class DatabasePDO
try
{
if
(
empty
(
self
::
$preparedQueries
[
$queryString
]))
{
$query
=
self
::
$
pdo
->
prepare
(
$queryString
);
$query
=
$this
->
pdo
->
prepare
(
$queryString
);
self
::
$preparedQueries
[
$queryString
]
=
$query
;
}
else
{
$query
=
self
::
$preparedQueries
[
$queryString
];
...
...
@@ -159,16 +151,16 @@ class DatabasePDO
$query
->
execute
(
$data
);
}
catch
(
\PDOException
$PDOException
)
{
if
(
strpos
(
$PDOException
->
getMessage
(),
'Admin shutdown: 7'
)
!==
false
)
{
$db
=
self
::
Database
([
'persistent'
=>
false
]);
if
(
empty
(
$db
::
$preparedQueries
[
$queryString
]))
{
$query
=
$db
::
$pdo
->
prepare
(
$queryString
);
self
::
$preparedQueries
[
$queryString
]
=
$query
;
if
(
strpos
(
$PDOException
->
getMessage
(),
'Admin shutdown: 7'
)
!==
false
||
strpos
(
$PDOException
->
getMessage
(),
'General error: 7'
)
!==
false
)
{
$db
=
new
DatabasePDO
();
if
(
$originalData
)
{
$db
->
query
(
$originalQuery
,
$originalData
);
}
else
{
$query
=
$db
::
$preparedQueries
[
$queryString
]
;
$
db
->
query
(
$originalQuery
)
;
}
$query
->
execute
(
$data
);
}
else
{
$param
=
implode
(
', '
,
$data
);
$file
=
fopen
(
'queries_error.log'
,
'a'
);
...
...
@@ -206,7 +198,7 @@ class DatabasePDO
public
static
function
reset
()
{
self
::
$
pdo
=
null
;
$this
->
pdo
=
null
;
self
::
$preparedQueries
=
[];
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment