Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
O
osticket
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
docker
osticket
Commits
f7ef9ea4
Commit
f7ef9ea4
authored
12 years ago
by
Peter Rotich
Browse files
Options
Downloads
Patches
Plain Diff
Use connection error message on connect error. Decouple DB selection from connection
parent
303c0370
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
include/mysql.php
+20
-16
20 additions, 16 deletions
include/mysql.php
main.inc.php
+4
-3
4 additions, 3 deletions
main.inc.php
setup/inc/class.installer.php
+1
-1
1 addition, 1 deletion
setup/inc/class.installer.php
with
25 additions
and
20 deletions
include/mysql.php
+
20
−
16
View file @
f7ef9ea4
...
...
@@ -2,7 +2,7 @@
/*********************************************************************
mysql.php
Collection of MySQL helper interface functions.
Collection of MySQL helper interface functions.
Mostly wrappers with error/resource checking.
...
...
@@ -16,8 +16,8 @@
vim: expandtab sw=4 ts=4 sts=4:
**********************************************************************/
function
db_connect
(
$host
,
$user
,
$passwd
,
$
db
=
""
)
{
function
db_connect
(
$host
,
$user
,
$passwd
,
$
options
=
NULL
)
{
//Assert
if
(
!
strlen
(
$user
)
||
!
strlen
(
$passwd
)
||
!
strlen
(
$host
))
return
NULL
;
...
...
@@ -27,7 +27,7 @@
return
NULL
;
//Select the database, if any.
if
(
$
db
)
db_select_database
(
$
db
);
if
(
$
options
[
'db'
]
)
db_select_database
(
$
options
[
'db'
]
);
//set desired encoding just in case mysql charset is not UTF-8 - Thanks to FreshMedia
@
mysql_query
(
'SET NAMES "utf8"'
);
...
...
@@ -36,7 +36,7 @@
@
db_set_variable
(
'sql_mode'
,
''
);
return
$dblink
;
return
$dblink
;
}
function
db_close
()
{
...
...
@@ -47,7 +47,7 @@
function
db_version
()
{
$version
=
0
;
if
(
preg_match
(
'/(\d{1,2}\.\d{1,2}\.\d{1,2})/'
,
if
(
preg_match
(
'/(\d{1,2}\.\d{1,2}\.\d{1,2})/'
,
mysql_result
(
db_query
(
'SELECT VERSION()'
),
0
,
0
),
$matches
))
# nolint
$version
=
$matches
[
1
];
# nolint
...
...
@@ -77,17 +77,17 @@
function
db_create_database
(
$database
,
$charset
=
'utf8'
,
$collate
=
'utf8_general_ci'
)
{
return
@
mysql_query
(
sprintf
(
'CREATE DATABASE %s DEFAULT CHARACTER SET %s COLLATE %s'
,
$database
,
$charset
,
$collate
));
}
// execute sql query
function
db_query
(
$query
,
$database
=
""
,
$conn
=
""
)
{
global
$ost
;
if
(
$conn
)
{
/* connection is provided*/
$res
=
(
$database
)
?
mysql_db_query
(
$database
,
$query
,
$conn
)
:
mysql_query
(
$query
,
$conn
);
}
else
{
$res
=
(
$database
)
?
mysql_db_query
(
$database
,
$query
)
:
mysql_query
(
$query
);
}
if
(
!
$res
&&
$ost
)
{
//error reporting
$msg
=
'['
.
$query
.
']'
.
"
\n\n
"
.
db_error
();
$ost
->
logDBError
(
'DB Error #'
.
db_errno
(),
$msg
);
...
...
@@ -98,7 +98,7 @@
}
function
db_squery
(
$query
)
{
//smart db query...utilizing args and sprintf
$args
=
func_get_args
();
$query
=
array_shift
(
$args
);
$query
=
str_replace
(
"?"
,
"%s"
,
$query
);
...
...
@@ -108,7 +108,7 @@
return
db_query
(
$query
);
}
function
db_count
(
$query
)
{
function
db_count
(
$query
)
{
return
db_result
(
db_query
(
$query
));
}
...
...
@@ -126,7 +126,7 @@
function
db_fetch_field
(
$res
)
{
return
(
$res
)
?
mysql_fetch_field
(
$res
)
:
NULL
;
}
}
function
db_assoc_array
(
$res
,
$mode
=
false
)
{
if
(
$res
&&
db_num_rows
(
$res
))
{
...
...
@@ -159,13 +159,13 @@
function
db_free_result
(
$res
)
{
return
mysql_free_result
(
$res
);
}
function
db_output
(
$var
)
{
if
(
!
function_exists
(
'get_magic_quotes_runtime'
)
||
!
get_magic_quotes_runtime
())
//Sucker is NOT on - thanks.
return
$var
;
if
(
is_array
(
$var
))
if
(
is_array
(
$var
))
return
array_map
(
'db_output'
,
$var
);
return
(
!
is_numeric
(
$var
))
?
stripslashes
(
$var
)
:
$var
;
...
...
@@ -192,9 +192,13 @@
}
function
db_error
()
{
return
mysql_error
();
return
mysql_error
();
}
function
db_connect_error
()
{
return
db_error
();
}
function
db_errno
()
{
return
mysql_errno
();
}
...
...
This diff is collapsed.
Click to expand it.
main.inc.php
+
4
−
3
View file @
f7ef9ea4
...
...
@@ -201,9 +201,10 @@
'key'
=>
DBSSLKEY
);
if
(
!
db_connect
(
DBHOST
,
DBUSER
,
DBPASS
,
$options
)
||
!
db_select_database
(
DBNAME
))
{
$ferror
=
'Unable to connect to the database'
;
if
(
!
db_connect
(
DBHOST
,
DBUSER
,
DBPASS
,
$options
))
{
$ferror
=
'Unable to connect to the database -'
.
db_connect_error
();
}
elseif
(
!
db_select_database
(
DBNAME
))
{
$ferror
=
'Unknown or invalid database '
.
DBNAME
;
}
elseif
(
!
(
$ost
=
osTicket
::
start
(
1
))
||
!
(
$cfg
=
$ost
->
getConfig
()))
{
$ferror
=
'Unable to load config info from DB. Get tech support.'
;
}
...
...
This diff is collapsed.
Click to expand it.
setup/inc/class.installer.php
+
1
−
1
View file @
f7ef9ea4
...
...
@@ -81,7 +81,7 @@ class Installer extends SetupWizard {
//MYSQL: Connect to the DB and check the version & database (create database if it doesn't exist!)
if
(
!
$this
->
errors
)
{
if
(
!
db_connect
(
$vars
[
'dbhost'
],
$vars
[
'dbuser'
],
$vars
[
'dbpass'
]))
$this
->
errors
[
'db'
]
=
'Unable to connect to MySQL server.
Possibly invalid login info.'
;
$this
->
errors
[
'db'
]
=
'Unable to connect to MySQL server.
'
.
db_connect_error
()
;
elseif
(
db_version
()
<
$this
->
getMySQLVersion
())
$this
->
errors
[
'db'
]
=
sprintf
(
'osTicket requires MySQL %s or better!'
,
$this
->
getMySQLVersion
());
elseif
(
!
db_select_database
(
$vars
[
'dbname'
])
&&
!
db_create_database
(
$vars
[
'dbname'
]))
{
...
...
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