在PHP脚本中保留MySQL注释 [英] preserve MySQL comment in PHP script
问题描述
我一直在一个项目,我一直在开发MySQL命令交互式。我现在想使用PHP脚本运行MySQL命令。我这样做只是粘贴在MySQL命令,并使它们成一个PHP字符串。像这样...
$ queryStg =
update table1 set col1 = 1;
drop table table2;
;
$ sqlQuery = mysqli_multi_query($ mysqliLink,$ queryStg);
但是我一直不得不删除MySQL的注释来使它工作。我想保留这些意见。有办法做到吗?我试过在每个评论的结尾添加'\\\
',但我不能让这个工作。
例如如果我运行它会回来的错误...
$ queryStg =
-
update table1 set col1 = 1;
--another comment
drop table table2;
;
$ sqlQuery = mysqli_multi_query($ mysqliLink,$ queryStg);
完整代码使其有用
mysqliLink = new mysqli($ host,$ username,$ password,$ dbName);
$ queryStg =
- 一个mySQL注释
update table1 set col1 = 1;
--another comment
drop table table2;
;
$ sqlQuery = mysqli_multi_query($ mysqliLink,$ queryStg);
do {
if(mysqli_error($ mysqliLink)){
die(ERROR:。
htmlspecialchars(mysqli_error($ mysqliLink),ENT_QUOTES)。
< br> \\\
);
}
echo mysqli_affected_rows($ mysqliLink);
mysqli_use_result($ mysqliLink);
$ moreResults = mysqli_more_results($ mysqliLink);
@mysqli_next_result($ mysqliLink);
} while($ moreResults);
感谢
select * from
- comment
atable
转换为select * from - comment atable
MySQL也允许这种类型的注释:
/ *注释结束* /
select * from
/ * comment * /
atable
转换为select * from / * comment * / atable
这样做: - )。
查看: http://dev.mysql.com/doc/refman/5.1/en/comments.html
I have been working on a project where I've been developing the MySQL commands interactively. I now want to run the MySQL commands using a PHP script. I do this by simply pasting in the MySQL commands and making them into a PHP string. Like this...
$queryStg = "
update table1 set col1 = 1;
drop table table2;
";
$sqlQuery = mysqli_multi_query($mysqliLink, $queryStg);
However I've always had to strip out the MySQL comments to get it to work. I'd prefer to retain these comments. Is there a way to do this?. I've tried adding '\n' at the end of each comment but I cant get this to work. E.g. if I run this it will come back with errors...
$queryStg = "
-- a mySQL comment
update table1 set col1 = 1;
--another comment
drop table table2;
";
$sqlQuery = mysqli_multi_query($mysqliLink, $queryStg);
Full code incase its useful
$mysqliLink = new mysqli ($host, $username, $password, $dbName);
$queryStg = "
-- a mySQL comment
update table1 set col1 = 1;
--another comment
drop table table2;
";
$sqlQuery = mysqli_multi_query($mysqliLink, $queryStg);
do {
if ( mysqli_error($mysqliLink) ) {
die("ERROR: " .
htmlspecialchars(mysqli_error($mysqliLink), ENT_QUOTES) .
"<br>\n");
}
echo mysqli_affected_rows($mysqliLink);
mysqli_use_result($mysqliLink);
$moreResults = mysqli_more_results($mysqliLink);
@mysqli_next_result($mysqliLink);
} while($moreResults);
Thanks
"select * from
-- comment
atable"
Gets translated into "select * from -- comment atable"
MySQL also allows this type of comments:
/*comment that ends*/
"select * from
/*comment*/
atable"
Gets translated into "select * from /*comment*/ atable"
And that does work :-).
See: http://dev.mysql.com/doc/refman/5.1/en/comments.html
这篇关于在PHP脚本中保留MySQL注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!