Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2022-089
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
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
Deshini Perera
2022-089
Commits
109ff120
Commit
109ff120
authored
Oct 08, 2022
by
Deshini Perera
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new file
parent
4933159c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
0 deletions
+25
-0
DB_Connector.py
DB_Connector.py
+25
-0
No files found.
DB_Connector.py
0 → 100644
View file @
109ff120
import
mysql.connector
from
mysql.connector
import
Error
def
DB_Connector
():
try
:
connection
=
mysql
.
connector
.
connect
(
host
=
'localhost'
,
database
=
'CDAP_PR_DB'
,
user
=
'DBUSER'
,
password
=
'PWD123'
)
if
connection
.
is_connected
():
db_Info
=
connection
.
get_server_info
()
print
(
"Connected to MySQL Server version "
,
db_Info
)
cursor
=
connection
.
cursor
()
cursor
.
execute
(
"select database();"
)
record
=
cursor
.
fetchone
()
print
(
"You're connected to database: "
,
record
)
except
Error
as
e
:
print
(
"Error while connecting to MySQL"
,
e
)
finally
:
if
connection
.
is_connected
():
cursor
.
close
()
connection
.
close
()
print
(
"MySQL connection is closed"
)
\ No newline at end of file
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