Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Python manipulates how MySQL reads pictures from the database

2025-01-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how Python operates MySQL to read pictures from a database. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Read the picture from the database

Import MySQLdb as mdbimport systry:# connects to mysql and gets the connected object conn = mdb.connect ('localhost',' root', 'root',' test') Cursor = conn.cursor () # query the SQLcursor.execute ("SELECT Data FROM Images LIMIT 1") of the picture field # use the binary write method to open an image file If it does not exist, automatically create fout = open ('image.png','wb') # directly send data such as file fout.write (cursor.fetchone () [0]) # close the written file fout.close () # release the resource cursor.close () conn.close () except IOError for querying the data, and EVL # catch the exception of IO The main reason is that there will be an error in file writing print "Error% d:% s"% (e.args [0], e.args [1]) sys.exit (1) Thank you for reading! On "Python operation MySQL how to read pictures from the database" this article is shared here, I hope the above content can be of some help to you, so that you can learn more knowledge, if you think the article is good, you can share it out for more people to see it!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report