Python MySQL Learning-output a result set of specified criteria

Source: Internet
Author: User

1 #Introducing the Pymysql module2 ImportPymysql as PM3 4 #Database Connection5db = Pm.connect (host='localhost', user='Root', password="123456", database='Task', charset='UTF8')6 #Creating Cursors7Cur =db.cursor ()8 #setting up SQL statements9sql ='SELECT * from Video_info WHERE actor_name=%s'Ten #Execute SQL statement OneCur.execute (SQL,'Andy Lau') A #Save a qualifying result set -Results =Cur.fetchall () - #Print result set the Print(Results) - #closing cursors and disconnecting database connections - cur.close () -Db.close ()

Test results:

Python MySQL Learning-output a result set of specified criteria

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.