根据文本文件调整MySQL数据库 [英] Adapt MySQL database according to text file

查看:109
本文介绍了根据文本文件调整MySQL数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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



文件格式为



\ N     Title     年    情节    评级



在我的PHP文件,我有这段代码:



  if (!mysqli_query($ con,< span class =code-string>  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数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆