Commit 109ff120 authored by Deshini Perera's avatar Deshini Perera

Add new file

parent 4933159c
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment