Last active
June 23, 2019 16:38
-
-
Save avielb/f5acbb843c5ec9e09706011807debe5f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
docker run --name some-mysql -e MYSQL_ROOT_PASSWORD=my-secret-pw -p 3306:3306 -d mysql:5.7 | |
SELECT * | |
FROM `1703`.users; | |
INSERT | |
INTO `1703`.users | |
VALUES ("Moshe","ben david", 50); | |
UPDATE `1703`.users | |
SET age = 51 | |
WHERE firstname = "Moshe"; | |
DELETE | |
FROM `1703`.users | |
WHERE firstname = "Aviel"; | |
--- | |
import pymysql | |
conn = pymysql.connect(host = 'localhost', port=3306, user='root', passwd='my-secret-pw', db='1703', autocommit=True) | |
cursor = conn.cursor() | |
cursor.execute("select * from users") | |
for row in cursor: | |
print(row) | |
cursor.close() | |
conn.close() | |
--- | |
import pymysql | |
conn = pymysql.connect(host = 'localhost', port=3306, user='root', passwd='my-secret-pw', db='1703', autocommit=True) | |
cursor = conn.cursor() | |
def add_animal(name, legs): | |
cursor.execute("INSERT INTO zoo VALUES ('" + name + "'," + str(legs) + ")") | |
print("added " + name) | |
def delete_animal(name): | |
cursor.execute("DELETE FROM zoo WHERE name = " + name) | |
def show_animals(): | |
cursor.execute("SELECT name FROM zoo") | |
return cursor | |
while(True): | |
print("1. add animal") | |
print("2. delete animal") | |
print("3. show animal") | |
action = input("What to do?") | |
if (action == "1"): | |
name_of_animal = input("enter name") | |
legs_of_animal = input("enter legs") | |
add_animal(name_of_animal, legs_of_animal) | |
if (action == "2"): | |
name_of_animal = input("enter name") | |
delete_animal(name_of_animal) | |
if(action == "3"): | |
result = show_animals() | |
for row in result: | |
print(row) | |
if (action == "q"): | |
break | |
cursor.close() | |
conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment