examples/example.py
raw| 1 | import asyncio |
| 2 | import aiomysql |
| 3 | |
| 4 | |
| 5 | async def test_example(loop): |
| 6 | conn = await aiomysql.connect(host='127.0.0.1', port=3306, |
| 7 | user='root', password='', db='mysql', |
| 8 | loop=loop) |
| 9 | |
| 10 | async with conn.cursor() as cur: |
| 11 | await cur.execute("SELECT Host,User FROM user") |
| 12 | print(cur.description) |
| 13 | r = await cur.fetchall() |
| 14 | print(r) |
| 15 | conn.close() |
| 16 | |
| 17 | |
| 18 | loop = asyncio.get_event_loop() |
| 19 | loop.run_until_complete(test_example(loop)) |