gpt4 book ai didi

php - 使用python获取存储在mysql表中的文本文件

转载 作者:行者123 更新时间:2023-11-29 21:01:17 24 4
gpt4 key购买 nike

在我的项目中,我有一个名为“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'

您还可以使用文件的绝对路径,但通常使用相对路径被认为是最佳实践,这样您的网站就不会绑定(bind)到当前部署位置的基本路径。例如,它将能够在本地主机以及您的公共(public)域上工作,无需修改

关于php - 使用python获取存储在mysql表中的文本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37203020/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com