如何将变化的数据存储到数据库中?
我制作了一个应用程序,从互联网广播流中获取正在播放的标题和艺术家,并在此页面上以纯文本形式显示它:
http://thelisthq.net/z1035.php
输出只是一个 php 'echo $variable' 命令,但是 $variable 不断变化,那么如何存储 $variable 的每个不同值到数据库中。 最终计划保留一段时间内播放的所有歌曲的列表。
I made an application to take the now playing title and artist from an internet radio stream, and I have it displaying in plain text on this page:
http://thelisthq.net/z1035.php
The output is simply a php 'echo $variable' command, but $variable is constantly changing, so how do I store each different value of $variable into a database. The end plan to to keep a list of all the songs that play over a certain period of time.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须将 php 脚本设置为每 x 分钟左右运行一次,而不是回显结果,而是根据当前播放的歌曲检查最新的数据库条目,如果不同,则添加新记录。
首先,使用一些 SQL 来设置新表:
然后,修改 PHP 脚本以在数据库中插入记录,而不是回显到屏幕:
设置计划任务或 cron 作业来运行 php -f z1035.php 每分钟。
要查看完整的歌曲列表,请创建一个新的 php 文件
station_history.php
You'll have to set up the php script to run every x minutes or so, and instead of echoing the result, check the most recent database entry against the currently playing song, and if it is different, add a new record.
First, some SQL to set up a new table:
Then, modify your PHP script to insert records in the database instead of echoing to the screen:
Set up a scheduled task or a cron job to run
php -f z1035.php
every minute.To see the entire list of songs, create a new php file
station_history.php