需要一些PHP / MySQL INSERT语句的帮助 [英] Need some help with multiple PHP/MySQL INSERT statements

查看:60
本文介绍了需要一些PHP / MySQL INSERT语句的帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个文件(add2db.txt)中有一个数据文本文件,其中条目是

已经在以下格式的单独行中输入:


INSERT INTO`Reviews`VALUES(",Tony''s's",Lunch,Great atmosphere。

Good food。,(Harry) Houdini - 03/01/2004)");


INSERT INTO` reviews` VALUES(",Le Chow Place,Lunch," yada yada",

"(Herbert Hoover - 03/03/2004)");


INSERT INTO` reviews` VALUES("" ;,Golden Dragon,Lunch,Exquisite。

Good food。,(Minnie Mouse - 01/03/2004)");


等等


这些已经从客户已经提交的评论表中解析过。在我查看信息之后我需要做什么

的适当性和语法是将它插入我的MySQL数据库。

我会写这样的单行条目:


//设置Mysql变量

$ host =" localhost" ;;

$ user =" root" ;;

$ pass ="" ;;

$ db =" rest";

$ table =" reviews" ;;

//连接到Mysql,选择正确的数据库,然后运行查询

,将从文件中收集的数据添加到数据库中


mysql_connect($ host,$ user,$ pass)或die(mysql_error());

mysql_select_db($ db)或die(mysql_error());

$ add_review =" INSERT INTO $ table

values('''''''$ rname'''''$ umeal'',''$ ucomment'',''$ uname'' )" ;

mysql_query($ add_all)或死(mysql_error());

但是我怎么写$ add_review来读取
$ b的每一行$ b add2db.txt并将其作为单独的条目输入?

I have a text file of data in a file (add2db.txt) where the entries are
already entered on separate lines in the following form:

INSERT INTO `reviews` VALUES("", "Tony''s", "Lunch", "Great atmosphere.
Good food.", " (Harry Houdini - 03/01/2004)");

INSERT INTO `reviews` VALUES("", "Le Chow Place", "Lunch", "yada yada",
" (Herbert Hoover - 03/03/2004)");

INSERT INTO `reviews` VALUES("", "Golden Dragon", "Lunch", "Exquisite.
Good food.", " (Minnie Mouse - 01/03/2004)");

etc etc

These have been parsed from a review form that a client already
submitted. What I need to do now after I have reviewed the information
for appropriateness and grammer is to insert it into my MySQL database.
I would write single line entries like this:

// Set Mysql Variables
$host = "localhost";
$user = "root";
$pass = "";
$db = "rest";
$table = "reviews";
// Connect to Mysql, select the correct database, and run the query
which adds the data gathered from the file into the database

mysql_connect($host,$user,$pass) or die(mysql_error());
mysql_select_db($db) or die(mysql_error());
$add_review = "INSERT INTO $table
values('''',''$rname'',''$umeal'',''$ucomment'',''$uname'')" ;
mysql_query($add_all) or die(mysql_error());
But how would I write the $add_review to read each line of the
add2db.txt and enter it as a separate entry?

推荐答案

host =" localhost";
host = "localhost";


user =" root";
user = "root";


pass ="" ;;
pass = "";

这篇关于需要一些PHP / MySQL INSERT语句的帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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