MyEasySQL is a simple Python library to interact with MySQL databases. It provides functions to connect to a database, execute queries, and retrieve data from specific columns or cells.
To install myeasysql, run:
pip install myeasysqlUse the connect function to establish a connection to the MySQL database:
import myeasysql as sql
cnx = sql.connect('your_host', 'your_user', 'your_password', 'your_database')Use the command function to execute a query and fetch results:
result = sql.command(cnx, 'your_command')
print(result)Use the rawCommand function to execute a query and fetch unformatted results:
raw_result = sql.rawCommand(cnx, 'your_command')
print(raw_result)Use the getColumn function to retrieve all values from a specific column in a table:
column_data = sql.getColumn(cnx, 'your_table', 'your_column')
print(column_data)Use the getCell function to retrieve a specific cell value from a table:
cell_value = sql.getCell(cnx, 'your_table', 'your_column', rowIndex)
print(cell_value)Use the getRow function to retrieve all values from a specific row in a table:
row_data = sql.getRow(cnx, 'your_table', rowIndex)
print(row_data)Use the isEven function to check if a number is even:
print(sql.isEven(4)) # Outputs: True
print(sql.isEven(5)) # Outputs: FalseUse the getLength function to get the number of rows in a table:
table_length = sql.getLength(cnx, 'your_table')
print(table_length)connect(host, user, password, database): Connects to the MySQL database.command(cnx, query): Executes a query and returns the formatted results.rawCommand(cnx, query): Executes a query and returns unformatted results.getColumn(cnx, table, column): Retrieves all values from a specific column.getCell(cnx, table, column, rowIndex): Retrieves a specific cell value from a table.getRow(cnx, table, rowIndex): Retrieves all values from a specific row in a table.getLength(cnx, table): Retrieves the number of rows in a table.isEven(n): ReturnsTrueif the number is even, otherwiseFalse.