[英]Fetch a text file stored in mysql table using python
在我的項目中,我有一個名為“ uploadedfile”的數據庫,用於將“ demo.txt”文件存儲到mysql數據庫中的mysql表“ file”中。 現在,我想在我的python文件中使用該.txt文件將其轉換為.xml文件。
我的問題是:
如何以文件格式從mysql數據庫表中獲取該.txt文件?
將其轉換為.xml文件后,如何將該文件上傳到同一“ uploadedfile”數據庫中的“ xml”表中,以便PHP可以檢索該文件以進行下載。
Please suggest if there is any way to proceed or is there any alternative way to do this. Please.
My SQL queries explaining the details of my schema are:
mysql> SHOW DATABASES;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| uploadedfile |
+--------------------+
4 rows in set (0.03 sec)
mysql> USE uploadedfile;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> SHOW TABLES;
+------------------------+
| Tables_in_uploadedfile |
+------------------------+
| file |
+------------------------+
1 row in set (0.00 sec)
mysql> DESCRIBE file;
+---------+---------------------+------+-----+--------------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+---------------------+------+-----+--------------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| name | varchar(255) | NO | | Untitled.txt | |
| mime | varchar(50) | NO | | text/plain | |
| size | bigint(20) unsigned | NO | | 0 | |
| data | mediumblob | NO | | NULL | |
| created | datetime | NO | | NULL | |
+---------+---------------------+------+-----+--------------+----------------+
6 rows in set (0.00 sec)
mysql> SELECT * FROM file where name="fourth.txt";
+----+------------+------------+------+------+---------------------+
| id | name | mime | size | data | created |
+----+------------+------------+------+------+---------------------+
| 3 | fourth.txt | text/plain | 8785 | | 2016-05-13 10:47:29 |
+----+------------+------------+------+------+---------------------+
1 row in set (0.00 sec)
I need this fourth.txt to get converted to .xml using my python script.
But I am stuck as how to fetch that file from mySQL database.
Please help
您可以使用該文件的相對路徑來獲取它,例如
'folder_name/' + 'file name from DB'
您也可以使用文件的絕對路徑,但是通常認為使用相對路徑是最佳實踐,這樣您的網站就不會綁定到當前部署位置的基本路徑。 例如,它無需修改即可在localhost以及您的公共域上工作
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.