根据文本文件调整MySQL数据库

编程入门 行业动态 更新时间:2024-10-27 07:16:52
本文介绍了根据文本文件调整MySQL数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在做一个电影数据库项目来学习MySQL和PHP。到目前为止,我用Python搜索文件夹,看看是否添加或删除了文件。如果它检测到添加或删除了文件,它将运行另一个获取电影文件名称的Python脚本,然后搜索OMDb并返回某些值(如标题,年份,图表,评级等)。然后将此信息存储到供MySQL使用的文件中。 文件格式为 \ N Title 年情节评级 在我的PHP文件,我有这段代码:

if (!mysqli_query($ con, LOAD DATA LOCAL INFILE'/home/user/movies.txt'INTO TABLE films)){ printf( Errormessage:%s \ n,mysqli_error($ con)); } $ result = mysqli_query($ con, SELECT title,yr,genre,plot,rating FROM films)或 die( 无法查询。);

然后在那之后我有一个循环,回显一些HTML来生成一个表。 一切正常。当我添加文件时,Python会检测到它,从互联网上获取电影信息并将信息添加到文件中,然后PHP将该信息加载到MySQL数据库然后显示它。 然而,当我从Python查找的目录中删除文件时,MySQL数据库的文件会更新,但MySQL仍然在数据库中删除了电影/文件。 我怎样才能让MySQL(通过PHP)从文件中加载数据,但是替换它而不是追加它?

解决方案 CON, LOAD DATA LOCAL INFILE '/home/user/movies.txt' INTO表电影)){ printf( Errormessage:%s \ n,mysqli_error(

con)); }

result = mysqli_query(

I'm doing a movie database project to learn MySQL and also PHP. So far, I've Python to search a folder and see if a file was added or removed. If it has detected that a file was added or removed, it will run another Python script that gets the name of the movie file and then searches OMDb and returns certain values (like title, year, plot, rating, etc). This information is then stored into a file for MySQL to use. The file is formatted like "\N Title Year Plot Rating" In my PHP file I have this code:

if (!mysqli_query($con, "LOAD DATA LOCAL INFILE '/home/user/movies.txt' INTO TABLE films")) { printf("Errormessage: %s\n", mysqli_error($con)); } $result = mysqli_query($con, "SELECT title, yr, genre, plot, rating FROM films") or die("Unable to query.");

And then after that I have a loop which echoes some HTML to produce a table. This all works fine. When I add a file, Python detects it, gets the movie info from the internet and adds the info to a file, and then PHP loads that information to a MySQL database and then displays it. However, when I remove a file from the directory that Python looks in, the file for the MySQL db is updated, but MySQL still has the removed movie/file in the database. How could I get MySQL (through PHP) to load the data from the file, but replacing it instead of appending it?

解决方案

con, "LOAD DATA LOCAL INFILE '/home/user/movies.txt' INTO TABLE films")) { printf("Errormessage: %s\n", mysqli_error(

con)); }

result = mysqli_query(

更多推荐

根据文本文件调整MySQL数据库

本文发布于:2023-07-09 00:20:21,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1082125.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文本文件   数据库   MySQL

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!