当前位置: 首页>>代码示例>>Python>>正文


Python MySQLConnection.is_connected方法代码示例

本文整理汇总了Python中mysql.connector.MySQLConnection.is_connected方法的典型用法代码示例。如果您正苦于以下问题:Python MySQLConnection.is_connected方法的具体用法?Python MySQLConnection.is_connected怎么用?Python MySQLConnection.is_connected使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mysql.connector.MySQLConnection的用法示例。


在下文中一共展示了MySQLConnection.is_connected方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: query_row

# 需要导入模块: from mysql.connector import MySQLConnection [as 别名]
# 或者: from mysql.connector.MySQLConnection import is_connected [as 别名]
def query_row(table):
    """Returns the next row of a query result set or None

        str -> tuple"""
    try:
        dbconfig = read_db_config()  # returns a dict of connection parameters
        print("Connecting " + dbconfig["user"] + " to " + dbconfig["database"] + "...")
        conn = MySQLConnection(**dbconfig)
        if conn.is_connected():
            print("Connection established.")
        else:
            print("Connection failed")

        cursor = conn.cursor(buffered=True)
        sql_command = "SELECT * FROM " + table
        print("Executed command: " + sql_command + ".")
        cursor.execute(sql_command)

        row = cursor.fetchone()
        return row

        # The fetchall method is similar but memory-consuming
        # rows = cursor.fetchall()
        # print('Total rows:', cursor.rowcount)
        # return rows

    except Error as e:
        print(e)
    finally:
        cursor.close()
        conn.close()
开发者ID:iu-cewit,项目名称:database,代码行数:33,代码来源:py_my_fetch.py

示例2: Connect

# 需要导入模块: from mysql.connector import MySQLConnection [as 别名]
# 或者: from mysql.connector.MySQLConnection import is_connected [as 别名]
def Connect():

    kwargs = ReadingMySQLConfig()
    MyConnection = MySQLConnection(**kwargs)
    try:
        if MyConnection.is_connected():
            print("Connected")
    except Error as e:
        print(e)
    finally:
        MyConnection.close()
开发者ID:12reach,项目名称:FirstPythonProject,代码行数:13,代码来源:retrieve_by_dbconfig.py

示例3: connect

# 需要导入模块: from mysql.connector import MySQLConnection [as 别名]
# 或者: from mysql.connector.MySQLConnection import is_connected [as 别名]
def connect():
    """ Connect to MySQL database """

    dbConfig = readDbConfig()

    try:
        print('Connecting to MySQL database...')
        conn = MySQLConnection(**dbConfig)
        if(conn.is_connected()):
           print('Connected to database')
           return conn
        else:
            print('Failed to connect to database')
    except Error as error:
        print(error)
开发者ID:Tangeleno,项目名称:TempMonitor,代码行数:17,代码来源:MySqlConnect.py

示例4: __init__

# 需要导入模块: from mysql.connector import MySQLConnection [as 别名]
# 或者: from mysql.connector.MySQLConnection import is_connected [as 别名]
 def __init__(self):       
     global cursor
     global conn
   
     try:
         print('Connecting to MySQL database...')
         conn = MySQLConnection(user='root', password='New9835', database='geom') # Connect to MySQL database
         cursor = conn.cursor()
         
         if conn.is_connected():
             print('connection established.')
         else:
             print('connection failed.')   
     except Error as error:
         print(error)
开发者ID:Crypher19,项目名称:GeoM-Project,代码行数:17,代码来源:Database.py

示例5: connect

# 需要导入模块: from mysql.connector import MySQLConnection [as 别名]
# 或者: from mysql.connector.MySQLConnection import is_connected [as 别名]
def connect():

    db_config = read_db_config()

    try:
        print 'Connecting to database: {0}...'.format(db_config['database'])
        conn = MySQLConnection(**db_config)

        if conn.is_connected():
            print 'Connection established.'
            return conn
        else:
            print 'Connection failed.'

    except Error as e:
        print e.message
开发者ID:wenyaowu,项目名称:python_mysql,代码行数:18,代码来源:python_mysql.py

示例6: connect

# 需要导入模块: from mysql.connector import MySQLConnection [as 别名]
# 或者: from mysql.connector.MySQLConnection import is_connected [as 别名]
def connect():
    """Connect to MySQL database

        none -> none"""
    db_config = read_db_config()
    try:
        print('Connecting to MySQL database...')
        conn = MySQLConnection(**db_config)
        if conn.is_connected():
            print('Connection established.')
        else:
            print('Connection failed.')
    except Error as e:
        print(e)
    finally:
        conn.close()
        print('Connection closed.')
开发者ID:iu-cewit,项目名称:database,代码行数:19,代码来源:py_my_connect2.py

示例7: connect

# 需要导入模块: from mysql.connector import MySQLConnection [as 别名]
# 或者: from mysql.connector.MySQLConnection import is_connected [as 别名]
def connect():
	''' Connect to MySql Database'''
	db_config = read_db_config()
	print db_config
	try:
		conn = MySQLConnection(**db_config)
		print "Connecting to MySql database..."
		if conn.is_connected():
			print "Connection establish"
		else:
			print "Connection Failed"
	except Error as e:
		print "[SOMETHING BAD  HAPPEND...]",e
	
	finally:
		conn.close()
		print 'Connection Closed'
开发者ID:saqibmubarak,项目名称:Python_Workshop,代码行数:19,代码来源:python_mysql_connect.py

示例8: sql

# 需要导入模块: from mysql.connector import MySQLConnection [as 别名]
# 或者: from mysql.connector.MySQLConnection import is_connected [as 别名]
    def sql(self, args, **kwargs):

        if args == 'test':

            try:

                print('--- Connect to MySQL server:', self.__SQLhost)
                connect = MySQLConnection(host=self.__SQLhost, database=self.__SQLbase,
                                          user=self.__SQLuser, password=self.__SQLpass)

                if connect.is_connected():
                    print('--- Connected to MySQL database', self.__SQLbase)
                    connect.close()

            except SQLError as e:
                print('***', e)
                self.__systest = False
开发者ID:thzvm,项目名称:Python,代码行数:19,代码来源:vk.py

示例9: connect

# 需要导入模块: from mysql.connector import MySQLConnection [as 别名]
# 或者: from mysql.connector.MySQLConnection import is_connected [as 别名]
def connect(db_data):
    """ Connect to MySQL database """

    try:
        print('Connecting to MySQL database...')
        conn = MySQLConnection(**db_data)

        if conn.is_connected():
            print('connection established.')
        else:
            print('connection failed.')

    except Error as error:
        print(error)

    finally:
        conn.close()
        print('Connection closed.')
开发者ID:DoaneAS,项目名称:BioInfoFinal,代码行数:20,代码来源:make_db.py

示例10: connect

# 需要导入模块: from mysql.connector import MySQLConnection [as 别名]
# 或者: from mysql.connector.MySQLConnection import is_connected [as 别名]
def connect():
    """ Connect to MySQL database """

    db_config = read_db_config()

    try:
        print('Connecting to MySQL database...')
        conn = MySQLConnection(**db_config)

        if conn.is_connected():
            print('connection established.')
        else:
            print('connection failed.')

    except Error as error:
        print(error)

    return conn
开发者ID:Vasilesk,项目名称:twitter-posting-bot,代码行数:20,代码来源:mysql_operations.py

示例11: connecting

# 需要导入模块: from mysql.connector import MySQLConnection [as 别名]
# 或者: from mysql.connector.MySQLConnection import is_connected [as 别名]
def connecting():
 db_config = read_db_config()
 success = False
 
 try:
  print('Connecting to database....')
  mysqlConn = MySQLConnection(**db_config)
   
  if mysqlConn.is_connected():
   print('connection estabslished.')
   success = True
  else:
   print('connection failed')
  return mysqlConn
 
 except Error as err:
  print(err)
  return 
开发者ID:gruenerf,项目名称:Mobile-Media,代码行数:20,代码来源:myDbConnect.py

示例12: connect

# 需要导入模块: from mysql.connector import MySQLConnection [as 别名]
# 或者: from mysql.connector.MySQLConnection import is_connected [as 别名]
def connect(fName='../../conf/config.ini'):
    """ Connect to MySQL database """
 
    db_config = read_db_config(fName)
 
    try:
        print('Connecting to MySQL database...')
        conn = MySQLConnection(**db_config)
 
        if conn.is_connected():
            print('connection established.')
        else:
            print('connection failed.')
 
    except Error as error:
        print(error)
 
    finally:
        conn.close()
        print('Connection closed.')
开发者ID:SNET-Entrance,项目名称:gc_for_pubsub,代码行数:22,代码来源:mysql_dbconfig.py

示例13: connect

# 需要导入模块: from mysql.connector import MySQLConnection [as 别名]
# 或者: from mysql.connector.MySQLConnection import is_connected [as 别名]
def connect():
    """ Connect to MySQL database """

    db_config =  {'password': 'root', 'host': 'localhost', 'user': 'root', 'database': 'stats'}

    try:
        print('Connecting to MySQL database...')
        conn = MySQLConnection(**db_config)

        if conn.is_connected():
            print('connection established.')
        else:
            print('connection failed.')

    except Error as error:
        print(error)

    finally:
        conn.close()
        print('Connection closed.')
开发者ID:leenakhote,项目名称:python-graph,代码行数:22,代码来源:mysql_connect2.py

示例14: connect

# 需要导入模块: from mysql.connector import MySQLConnection [as 别名]
# 或者: from mysql.connector.MySQLConnection import is_connected [as 别名]
def connect():
    """Connect to mysql database"""
    db_config = read_db_config()
    try:
        """
		conn = mysql.connector.connect(host='localhost',
										database='python_mysql',
										user='root',
										password='tegbeton') """
        print("Connecting to MySQL databse...")
        conn = MySQLConnection(**db_config)

        if conn.is_connected():
            print("Connection established")
        else:
            print("connection failed.")
    except Error as e:
        print(e)
    finally:
        conn.close()
        print("Connection closed..!")
开发者ID:amaur,项目名称:LearnPython,代码行数:23,代码来源:learnOS.py

示例15: connect

# 需要导入模块: from mysql.connector import MySQLConnection [as 别名]
# 或者: from mysql.connector.MySQLConnection import is_connected [as 别名]
def connect():
    """ Connect to MySQL database """

    db_config = read_db_config("config.ini", "mysql")
    table_config = read_db_config("config.ini", "tabledata")

    try:
        print('Connecting to MySQL database...')
        conn = MySQLConnection(**db_config)

        if conn.is_connected():
            print('connection established.')
            spotifyCall(conn, table_config)
        else:
            print('connection failed.')

    except Error as error:
        print(error)

    finally:
        conn.close()
        print('Connection closed.')
开发者ID:digitalmusiclab,项目名称:alpha-web,代码行数:24,代码来源:test.py


注:本文中的mysql.connector.MySQLConnection.is_connected方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。