Python MySQL Easy Query is another version of my PySQL_Assistant
No querying needed~! Its intended purpose is to help beginners familiarize themselves with MySQL
How to use:
-
Define a function (steps 3-5 will be inside this function)
def ezQuery():
-
Create 4 variables. Make the value empty if you won't be using it:
host = ''
Your database host
user = ''
Your database username
passwd = ''
Your database password
db = ''
Your database name, if applicable -
Bind the object method EZ_Query to a var
dbo = PySQL_EZ_Query.EZ_Query(host, user, passwd, db)
-
Each queries are bound to a function, here's a sample for creating a database. All functions are listed below
dbo.create_database('pydb')
- create_database(
database_name)- create a database
- create_table(
table_name,columns)- columns should be written as a 'column1::, column2::, column3::, etc'
- double colon (::) after every column name is important
- keep your column names simple to prevent errors. camelCase or under_scores only
- ID is automatically generated, so no need to include one in the columns
- insert_into(
table_name,dictionary)- dictionary key must be the name of the column of the created table, dictionary value must be the column value
- select(
table_name)- show all records
- update(
table_name,column_to_update,new_value,record_id)- update record
- delete(
table_name,record_id)- delete selected record
- truncate(
table_name)- delete all data inside the table
- drop_table(
database_name)- deletes the table
- drop_database(
database_name)- deletes the database
import PySQL_EZ_Query
def ezQuery():
host = 'localhost'
user = 'root'
passwd = ''
db = ''
dbo = PySQL_EZ_Query.EZ_Query(host, user, passwd, db)
dbo.create_database('pydb')
ezQuery()
import PySQL_EZ_Query
def ezQuery():
host = 'localhost'
user = 'root'
passwd = ''
db = 'pydb'
dbo = PySQL_EZ_Query.EZ_Query(host, user, passwd, db)
table = 'customers'
columns = 'name::, address::'
dbo.create_table(table, columns)
ezQuery()
import PySQL_EZ_Query
def ezQuery():
host = 'localhost'
user = 'root'
passwd = ''
db = 'pydb'
dbo = PySQL_EZ_Query.EZ_Query(host, user, passwd, db)
table = 'customers'
data = {'name': 'Johnny', 'address': 'Highway 21'}
dbo.insert_into(table, data)
ezQuery()
import PySQL_EZ_Query
def ezQuery():
host = 'localhost'
user = 'root'
passwd = ''
db = 'pydb'
dbo = PySQL_EZ_Query.EZ_Query(host, user, passwd, db)
table = 'customers'
dbo.select(table)
ezQuery()
import PySQL_EZ_Query
def ezQuery():
host = 'localhost'
user = 'root'
passwd = ''
db = 'pydb'
dbo = PySQL_EZ_Query.EZ_Query(host, user, passwd, db)
table = 'customers'
column = 'name'
column_value = 'Henry'
record_id = 1
dbo.update(table, column, column_value, str(record_id))
ezQuery()
import PySQL_EZ_Query
def ezQuery():
host = 'localhost'
user = 'root'
passwd = ''
db = 'pydb'
dbo = PySQL_EZ_Query.EZ_Query(host, user, passwd, db)
table = 'customers'
id = 1
dbo.delete(table, str(id))
ezQuery()
import PySQL_EZ_Query
def ezQuery():
host = 'localhost'
user = 'root'
passwd = ''
db = 'pydb'
dbo = PySQL_EZ_Query.EZ_Query(host, user, passwd, db)
dbo.truncate('customers')
ezQuery()
import PySQL_EZ_Query
def ezQuery():
host = 'localhost'
user = 'root'
passwd = ''
db = 'pydb'
dbo = PySQL_EZ_Query.EZ_Query(host, user, passwd, db)
dbo.drop_table('customers')
ezQuery()
import PySQL_EZ_Query
def ezQuery():
host = 'localhost'
user = 'root'
passwd = ''
db = 'pydb'
dbo = PySQL_EZ_Query.EZ_Query(host, user, passwd, db)
dbo.drop_database('pydb')
ezQuery()
